aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-decl.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2010-05-15 20:07:01 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2010-05-15 20:07:01 +0100
commit4bdd0a60b27aa25d23cc19e4ab23163edf1a363b (patch)
tree58437182e5b92c32014bc05c7c720abea38f88b9 /gcc/c-decl.c
parentd025732d199d5fda6718e4e52661ae027421a5b4 (diff)
downloadgcc-4bdd0a60b27aa25d23cc19e4ab23163edf1a363b.zip
gcc-4bdd0a60b27aa25d23cc19e4ab23163edf1a363b.tar.gz
gcc-4bdd0a60b27aa25d23cc19e4ab23163edf1a363b.tar.bz2
c-decl.c (grokfield): Allow typedefs for anonymous structs and unions by default if...
* c-decl.c (grokfield): Allow typedefs for anonymous structs and unions by default if those structs and unions have no tags. Do not condition anonymous struct and unions handling on flag_iso. Allow anonymous structs and unions for C1X. (finish_struct): Do not diagnose lack of named fields when anonymous structs and unions present for C1X. Accept flexible array members in structure with anonymous structs or unions but no directly named fields. * doc/extend.texi (Unnamed Fields): Update. testsuite: * gcc.dg/c1x-anon-struct-1.c, gcc.dg/c1x-anon-struct-2.c, gcc.dg/c90-anon-struct-1.c, gcc.dg/c99-anon-struct-1.c: New tests. * gcc.dg/20080820.c, gcc.dg/anon-struct-1.c: Update expected diagnostics and type sizes. From-SVN: r159439
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r--gcc/c-decl.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 03211d6..4bec97f 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -6567,6 +6567,8 @@ grokfield (location_t loc,
Otherwise this is a forward declaration of a structure tag.
If this is something of the form "foo;" and foo is a TYPE_DECL, then
+ If foo names a structure or union without a tag, then this
+ is an anonymous struct (this is permitted by C1X).
If MS extensions are enabled and foo names a structure, then
again this is an anonymous struct.
Otherwise this is an error.
@@ -6580,14 +6582,11 @@ grokfield (location_t loc,
|| TREE_CODE (type) == UNION_TYPE);
bool ok = false;
- if (type_ok
- && (flag_ms_extensions || !declspecs->typedef_p))
+ if (type_ok)
{
if (flag_ms_extensions)
ok = true;
- else if (flag_iso)
- ok = false;
- else if (TYPE_NAME (type) == NULL)
+ else if (TYPE_NAME (TYPE_MAIN_VARIANT (type)) == NULL)
ok = true;
else
ok = false;
@@ -6597,7 +6596,15 @@ grokfield (location_t loc,
pedwarn (loc, 0, "declaration does not declare anything");
return NULL_TREE;
}
- pedwarn (loc, OPT_pedantic, "ISO C doesn%'t support unnamed structs/unions");
+ if (!flag_isoc1x)
+ {
+ if (flag_isoc99)
+ pedwarn (loc, OPT_pedantic,
+ "ISO C99 doesn%'t support unnamed structs/unions");
+ else
+ pedwarn (loc, OPT_pedantic,
+ "ISO C90 doesn%'t support unnamed structs/unions");
+ }
}
value = grokdeclarator (declarator, declspecs, FIELD, false,
@@ -6789,8 +6796,14 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes,
if (pedantic)
{
for (x = fieldlist; x; x = TREE_CHAIN (x))
- if (DECL_NAME (x) != 0)
- break;
+ {
+ if (DECL_NAME (x) != 0)
+ break;
+ if (flag_isoc1x
+ && (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE
+ || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE))
+ break;
+ }
if (x == 0)
{
@@ -6893,7 +6906,9 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes,
pedwarn (DECL_SOURCE_LOCATION (x), OPT_pedantic,
"invalid use of structure with flexible array member");
- if (DECL_NAME (x))
+ if (DECL_NAME (x)
+ || TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE
+ || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE)
saw_named_field = 1;
}