aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJoseph Myers <jsm@polyomino.org.uk>2004-10-10 01:47:20 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2004-10-10 01:47:20 +0100
commit216a5f1b3fd8bc312748ff226ab5e3c9c2db273c (patch)
treef192e170635c25ee19d58894e6355d869f6e0d82 /gcc
parentfb643d23f7fae28aa40eaacb0b23db038feece8e (diff)
downloadgcc-216a5f1b3fd8bc312748ff226ab5e3c9c2db273c.zip
gcc-216a5f1b3fd8bc312748ff226ab5e3c9c2db273c.tar.gz
gcc-216a5f1b3fd8bc312748ff226ab5e3c9c2db273c.tar.bz2
re PR c/17189 (bogus warning for struct Foo { int; };)
PR c/17189 * c-decl.c (grokfield): Make diagnostic for bad cases of unnamed fields a pedwarn. Pedwarn here for unnamed structs/unions if pedantic. * c-parse.in (component_decl): Don't pedwarn here for unnamed fields. testsuite: * gcc.dg/anon-struct-5.c: New test. From-SVN: r88834
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/c-decl.c22
-rw-r--r--gcc/c-parse.in3
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/anon-struct-5.c7
5 files changed, 33 insertions, 13 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index d2c0bae..2437467 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2004-10-10 Joseph S. Myers <jsm@polyomino.org.uk>
+
+ PR c/17189
+ * c-decl.c (grokfield): Make diagnostic for bad cases of unnamed
+ fields a pedwarn. Pedwarn here for unnamed structs/unions if
+ pedantic.
+ * c-parse.in (component_decl): Don't pedwarn here for unnamed
+ fields.
+
2004-10-09 Zdenek Dvorak <dvorakz@suse.cz>
PR tree-optimization/17906
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index a723c25..f2f9a27 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -5003,27 +5003,29 @@ grokfield (struct c_declarator *declarator, struct c_declspecs *declspecs,
that took root before someone noticed the bug... */
tree type = declspecs->type;
+ bool type_ok = (TREE_CODE (type) == RECORD_TYPE
+ || TREE_CODE (type) == UNION_TYPE);
+ bool ok = false;
- if (type
- && (TREE_CODE (type) == RECORD_TYPE
- || TREE_CODE (type) == UNION_TYPE)
+ if (type_ok
&& (flag_ms_extensions || !declspecs->typedef_p))
{
if (flag_ms_extensions)
- ; /* ok */
+ ok = true;
else if (flag_iso)
- goto warn_unnamed_field;
+ ok = false;
else if (TYPE_NAME (type) == NULL)
- ; /* ok */
+ ok = true;
else
- goto warn_unnamed_field;
+ ok = false;
}
- else
+ if (!ok)
{
- warn_unnamed_field:
- warning ("declaration does not declare anything");
+ pedwarn ("declaration does not declare anything");
return NULL_TREE;
}
+ if (pedantic)
+ pedwarn ("ISO C doesn't support unnamed structs/unions");
}
value = grokdeclarator (declarator, declspecs, FIELD, false,
diff --git a/gcc/c-parse.in b/gcc/c-parse.in
index 3defcd0..e469677 100644
--- a/gcc/c-parse.in
+++ b/gcc/c-parse.in
@@ -1738,9 +1738,6 @@ component_decl:
/* Support for unnamed structs or unions as members of
structs or unions (which is [a] useful and [b] supports
MS P-SDK). */
- if (pedantic)
- pedwarn ("ISO C doesn't support unnamed structs/unions");
-
$$ = grokfield (build_id_declarator (NULL_TREE),
current_declspecs, NULL_TREE);
POP_DECLSPEC_STACK; }
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index bb101fd..dd56e1b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2004-10-10 Joseph S. Myers <jsm@polyomino.org.uk>
+
+ PR c/17189
+ * gcc.dg/anon-struct-5.c: New test.
+
2004-10-09 Joseph S. Myers <jsm@polyomino.org.uk>
PR c/17844
diff --git a/gcc/testsuite/gcc.dg/anon-struct-5.c b/gcc/testsuite/gcc.dg/anon-struct-5.c
new file mode 100644
index 0000000..f7d1278
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/anon-struct-5.c
@@ -0,0 +1,7 @@
+/* Test bad warning for anonymous int in structure. Bug 17189. */
+/* { dg-do compile } */
+/* { dg-options "-std=c99 -pedantic-errors" } */
+
+struct Foo { int; }; /* { dg-bogus "unnamed" } */
+/* { dg-error "error: declaration does not declare anything" "int;" { target *-*-* } 5 } */
+/* { dg-error "error: struct has no members" "no members" { target *-*-* } 5 } */