Commit dc8263bc by Jason Merrill Committed by Jason Merrill

decl.c (xref_tag): Handle attributes between 'class' and name.

	* decl.c (xref_tag): Handle attributes between 'class' and name.
	* parse.y (aggr): Likewise.
	* semantics.c (finish_class_definition): Likewise.
	* Makefile.in (EXPECTED): Adjust.
	* cp-tree.h: Declare flag_optional_diags and warn_multichar.
	* decl2.c: Define them.
	(lang_decode_option): Handle them.
	* lang-options.h: Add -foptional-diags.
	* class.c (finish_struct): Don't complain about multiple meanings of
	name if -fno-optional-diags.
	* decl.c (pushdecl_class_level): Likewise.
	* lex.c (real_yylex): Check warn_multichar.

From-SVN: r20994
parent c8fbcc35
1998-07-07 Jason Merrill <jason@yorick.cygnus.com>
* decl.c (xref_tag): Handle attributes between 'class' and name.
* parse.y (aggr): Likewise.
* semantics.c (finish_class_definition): Likewise.
* Makefile.in (EXPECTED): Adjust.
* cp-tree.h: Declare flag_optional_diags and warn_multichar.
* decl2.c: Define them.
(lang_decode_option): Handle them.
* lang-options.h: Add -foptional-diags.
* class.c (finish_struct): Don't complain about multiple meanings of
name if -fno-optional-diags.
* decl.c (pushdecl_class_level): Likewise.
* lex.c (real_yylex): Check warn_multichar.
1998-07-06 Jason Merrill <jason@yorick.cygnus.com> 1998-07-06 Jason Merrill <jason@yorick.cygnus.com>
* decl.c (lookup_tag): Use CP_DECL_CONTEXT. * decl.c (lookup_tag): Use CP_DECL_CONTEXT.
......
...@@ -215,7 +215,7 @@ parse.o : $(PARSE_C) $(CONFIG_H) $(CXX_TREE_H) $(srcdir)/../flags.h lex.h \ ...@@ -215,7 +215,7 @@ parse.o : $(PARSE_C) $(CONFIG_H) $(CXX_TREE_H) $(srcdir)/../flags.h lex.h \
$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(BIG_SWITCHFLAG) \ $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(BIG_SWITCHFLAG) \
`echo $(PARSE_C) | sed 's,^\./,,'` `echo $(PARSE_C) | sed 's,^\./,,'`
CONFLICTS = expect 21 shift/reduce conflicts and 42 reduce/reduce conflicts. CONFLICTS = expect 22 shift/reduce conflicts and 42 reduce/reduce conflicts.
$(PARSE_H) : $(PARSE_C) $(PARSE_H) : $(PARSE_C)
$(PARSE_C) : $(srcdir)/parse.y $(PARSE_C) : $(srcdir)/parse.y
@echo $(CONFLICTS) @echo $(CONFLICTS)
......
...@@ -4319,6 +4319,7 @@ finish_struct (t, list_of_fieldlists, attributes, warn_anon) ...@@ -4319,6 +4319,7 @@ finish_struct (t, list_of_fieldlists, attributes, warn_anon)
icv = NULL_TREE; icv = NULL_TREE;
if (icv if (icv
&& flag_optional_diags
/* Don't complain about constructors. */ /* Don't complain about constructors. */
&& name != constructor_name (current_class_type) && name != constructor_name (current_class_type)
/* Or inherited names. */ /* Or inherited names. */
......
...@@ -465,6 +465,9 @@ extern int flag_guiding_decls; ...@@ -465,6 +465,9 @@ extern int flag_guiding_decls;
and class qualifiers. */ and class qualifiers. */
extern int flag_do_squangling; extern int flag_do_squangling;
/* Nonzero if we want to issue diagnostics that the standard says are not
required. */
extern int flag_optional_diags;
/* C++ language-specific tree codes. */ /* C++ language-specific tree codes. */
#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) SYM, #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) SYM,
...@@ -1707,6 +1710,9 @@ extern int flag_detailed_statistics; ...@@ -1707,6 +1710,9 @@ extern int flag_detailed_statistics;
type signature of any virtual function in the base class. */ type signature of any virtual function in the base class. */
extern int warn_overloaded_virtual; extern int warn_overloaded_virtual;
/* Nonzero means warn about use of multicharacter literals. */
extern int warn_multichar;
/* in c-common.c */ /* in c-common.c */
extern void declare_function_name PROTO((void)); extern void declare_function_name PROTO((void));
extern void decl_attributes PROTO((tree, tree, tree)); extern void decl_attributes PROTO((tree, tree, tree));
......
...@@ -3740,6 +3740,7 @@ pushdecl_class_level (x) ...@@ -3740,6 +3740,7 @@ pushdecl_class_level (x)
tree icv = IDENTIFIER_CLASS_VALUE (name); tree icv = IDENTIFIER_CLASS_VALUE (name);
if (icv && icv != x if (icv && icv != x
&& flag_optional_diags
/* Don't complain about inherited names. */ /* Don't complain about inherited names. */
&& id_in_current_class (name) && id_in_current_class (name)
/* Or shadowed tags. */ /* Or shadowed tags. */
...@@ -11074,6 +11075,17 @@ xref_tag (code_type_node, name, binfo, globalize) ...@@ -11074,6 +11075,17 @@ xref_tag (code_type_node, name, binfo, globalize)
register tree ref, t; register tree ref, t;
struct binding_level *b = inner_binding_level; struct binding_level *b = inner_binding_level;
int got_type = 0; int got_type = 0;
tree attributes = NULL_TREE;
/* If we are called from the parser, code_type_node will sometimes be a
TREE_LIST. This indicates that the user wrote
"class __attribute__ ((foo)) bar". Extract the attributes so we can
use them later. */
if (TREE_CODE (code_type_node) == TREE_LIST)
{
attributes = TREE_PURPOSE (code_type_node);
code_type_node = TREE_VALUE (code_type_node);
}
tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node); tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
switch (tag_code) switch (tag_code)
...@@ -11249,6 +11261,8 @@ xref_tag (code_type_node, name, binfo, globalize) ...@@ -11249,6 +11261,8 @@ xref_tag (code_type_node, name, binfo, globalize)
pop_obstacks (); pop_obstacks ();
TREE_TYPE (ref) = attributes;
return ref; return ref;
} }
...@@ -12500,7 +12514,7 @@ finish_function (lineno, call_poplevel, nested) ...@@ -12500,7 +12514,7 @@ finish_function (lineno, call_poplevel, nested)
{ {
tree vb = get_vbase tree vb = get_vbase
(BINFO_TYPE (vbases), (BINFO_TYPE (vbases),
TYPE_BINFO (current_class_type)); TYPE_BINFO (current_class_type), 0);
expand_expr_stmt expand_expr_stmt
(build_scoped_method_call (build_scoped_method_call
(current_class_ref, vb, dtor_identifier, (current_class_ref, vb, dtor_identifier,
......
...@@ -195,6 +195,11 @@ int flag_vtable_thunks = DEFAULT_VTABLE_THUNKS; ...@@ -195,6 +195,11 @@ int flag_vtable_thunks = DEFAULT_VTABLE_THUNKS;
int flag_use_repository; int flag_use_repository;
/* Nonzero if we want to issue diagnostics that the standard says are not
required. */
int flag_optional_diags = 1;
/* Nonzero means give string constants the type `const char *' /* Nonzero means give string constants the type `const char *'
to get extra warnings from them. These warnings will be too numerous to get extra warnings from them. These warnings will be too numerous
to be useful, except in thoroughly ANSIfied programs. */ to be useful, except in thoroughly ANSIfied programs. */
...@@ -281,7 +286,11 @@ int warn_old_style_cast; ...@@ -281,7 +286,11 @@ int warn_old_style_cast;
/* Warn about #pragma directives that are not recognised. */ /* Warn about #pragma directives that are not recognised. */
int warn_unknown_pragmas = 0; /* Tri state variable. */ int warn_unknown_pragmas; /* Tri state variable. */
/* Nonzero means warn about use of multicharacter literals. */
int warn_multichar = 1;
/* Nonzero means `$' can be in an identifier. */ /* Nonzero means `$' can be in an identifier. */
...@@ -487,6 +496,7 @@ static struct { char *string; int *variable; int on_value;} lang_f_options[] = ...@@ -487,6 +496,7 @@ static struct { char *string; int *variable; int on_value;} lang_f_options[] =
{"nonansi-builtins", &flag_no_nonansi_builtin, 0}, {"nonansi-builtins", &flag_no_nonansi_builtin, 0},
{"gnu-keywords", &flag_no_gnu_keywords, 0}, {"gnu-keywords", &flag_no_gnu_keywords, 0},
{"operator-names", &flag_operator_names, 1}, {"operator-names", &flag_operator_names, 1},
{"optional-diags", &flag_optional_diags, 1},
{"check-new", &flag_check_new, 1}, {"check-new", &flag_check_new, 1},
{"repo", &flag_use_repository, 1}, {"repo", &flag_use_repository, 1},
{"for-scope", &flag_new_for_scope, 2}, {"for-scope", &flag_new_for_scope, 2},
...@@ -718,6 +728,10 @@ lang_decode_option (argc, argv) ...@@ -718,6 +728,10 @@ lang_decode_option (argc, argv)
warn_sign_promo = setting; warn_sign_promo = setting;
else if (!strcmp (p, "old-style-cast")) else if (!strcmp (p, "old-style-cast"))
warn_old_style_cast = setting; warn_old_style_cast = setting;
else if (!strcmp (p, "overloaded-virtual"))
warn_overloaded_virtual = setting;
else if (!strcmp (p, "multichar"))
warn_multichar = setting;
else if (!strcmp (p, "unknown-pragmas")) else if (!strcmp (p, "unknown-pragmas"))
/* Set to greater than 1, so that even unknown pragmas in /* Set to greater than 1, so that even unknown pragmas in
system headers will be warned about. */ system headers will be warned about. */
...@@ -743,6 +757,7 @@ lang_decode_option (argc, argv) ...@@ -743,6 +757,7 @@ lang_decode_option (argc, argv)
warn_sign_compare = setting; warn_sign_compare = setting;
warn_extern_inline = setting; warn_extern_inline = setting;
warn_nonvdtor = setting; warn_nonvdtor = setting;
warn_multichar = setting;
/* We save the value of warn_uninitialized, since if they put /* We save the value of warn_uninitialized, since if they put
-Wuninitialized on the command line, we need to generate a -Wuninitialized on the command line, we need to generate a
warning about not using it without also specifying -O. */ warning about not using it without also specifying -O. */
...@@ -754,9 +769,6 @@ lang_decode_option (argc, argv) ...@@ -754,9 +769,6 @@ lang_decode_option (argc, argv)
headers. */ headers. */
warn_unknown_pragmas = 1; warn_unknown_pragmas = 1;
} }
else if (!strcmp (p, "overloaded-virtual"))
warn_overloaded_virtual = setting;
else return strings_processed; else return strings_processed;
} }
else if (!strcmp (p, "-ansi")) else if (!strcmp (p, "-ansi"))
......
...@@ -75,6 +75,8 @@ Boston, MA 02111-1307, USA. */ ...@@ -75,6 +75,8 @@ Boston, MA 02111-1307, USA. */
"-fno-nonnull-objects", "-fno-nonnull-objects",
"-foperator-names", "-foperator-names",
"-fno-operator-names", "-fno-operator-names",
"-foptional-diags",
"-fno-optional-diags",
"-frepo", "-frepo",
"-fno-repo", "-fno-repo",
"-fsave-memoized", "-fsave-memoized",
......
...@@ -3971,7 +3971,7 @@ real_yylex () ...@@ -3971,7 +3971,7 @@ real_yylex ()
num_chars = max_chars; num_chars = max_chars;
error ("character constant too long"); error ("character constant too long");
} }
else if (num_chars != 1) else if (num_chars != 1 && warn_multichar)
warning ("multi-character character constant"); warning ("multi-character character constant");
/* If char type is signed, sign-extend the constant. */ /* If char type is signed, sign-extend the constant. */
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -2085,6 +2085,8 @@ aggr: ...@@ -2085,6 +2085,8 @@ aggr:
{ error ("type qualifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); } { error ("type qualifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
| aggr AGGR | aggr AGGR
{ error ("no body nor ';' separates two class, struct or union declarations"); } { error ("no body nor ';' separates two class, struct or union declarations"); }
| aggr attributes
{ $$ = build_decl_list ($2, $1); }
; ;
named_class_head_sans_basetype: named_class_head_sans_basetype:
......
...@@ -1299,6 +1299,11 @@ finish_class_definition (t, components, attributes, semi) ...@@ -1299,6 +1299,11 @@ finish_class_definition (t, components, attributes, semi)
if (semi) if (semi)
note_got_semicolon (t); note_got_semicolon (t);
/* If we got any attributes in class_head, xref_tag will stick them in
TREE_TYPE of the type. Grab them now. */
attributes = chainon (TREE_TYPE (t), attributes);
TREE_TYPE (t) = NULL_TREE;
if (TREE_CODE (t) == ENUMERAL_TYPE) if (TREE_CODE (t) == ENUMERAL_TYPE)
; ;
else else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment