diff options
author | Joseph Myers <jsm28@cam.ac.uk> | 2001-01-31 10:24:40 +0000 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2001-01-31 10:24:40 +0000 |
commit | 0aca1a4fd3d3f5fbfbbbfcc8e29a3f1cbb45d56a (patch) | |
tree | 34733a2dad346aaafe559de1ce988837b74efabf /gcc/c-decl.c | |
parent | 92fa350add2e10d97b012085da56166db9ed4f0c (diff) | |
download | gcc-0aca1a4fd3d3f5fbfbbbfcc8e29a3f1cbb45d56a.zip gcc-0aca1a4fd3d3f5fbfbbbfcc8e29a3f1cbb45d56a.tar.gz gcc-0aca1a4fd3d3f5fbfbbbfcc8e29a3f1cbb45d56a.tar.bz2 |
c-parse.in (structsp): Pedwarn when "enum foo" refers to an incomplete type.
* c-parse.in (structsp): Pedwarn when "enum foo" refers to an
incomplete type.
(typename): Call pending_xref_error after parsing typed_typespecs.
* c-decl.c (lookup_tag): Give error immediately rather than
leaving it pending if the tag of the wrong type is in the same
binding level.
(xref_tag): Don't pedwarn for forward declarations of enum types
here.
* gcc.texi (Actual Bugs): Remove entry for misuse of struct, union
and enum tags.
testsuite:
* gcc.dg/c99-tag-1.c: New test.
From-SVN: r39372
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r-- | gcc/c-decl.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c index edbe9ce..b49f786 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -2815,6 +2815,7 @@ lookup_tag (code, name, binding_level, thislevel_only) int thislevel_only; { register struct binding_level *level; + int thislevel = 1; for (level = binding_level; level; level = level->level_chain) { @@ -2829,12 +2830,22 @@ lookup_tag (code, name, binding_level, thislevel_only) pending_invalid_xref = name; pending_invalid_xref_file = input_filename; pending_invalid_xref_line = lineno; + /* If in the same binding level as a declaration as a tag + of a different type, this must not be allowed to + shadow that tag, so give the error immediately. + (For example, "struct foo; union foo;" is invalid.) */ + if (thislevel) + pending_xref_error (); } return TREE_VALUE (tail); } } - if (thislevel_only && ! level->tag_transparent) - return NULL_TREE; + if (! level->tag_transparent) + { + if (thislevel_only) + return NULL_TREE; + thislevel = 0; + } } return NULL_TREE; } @@ -5112,9 +5123,6 @@ xref_tag (code, name) ref = make_node (code); if (code == ENUMERAL_TYPE) { - /* (In ANSI, Enums can be referred to only if already defined.) */ - if (pedantic) - pedwarn ("ISO C forbids forward references to `enum' types"); /* Give the type a default layout like unsigned int to avoid crashing if it does not get defined. */ TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node); |