summaryrefslogtreecommitdiff
path: root/gcc/c-decl.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r--gcc/c-decl.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 4ec34eace4d..d167ddfd4c9 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -5392,6 +5392,18 @@ grokfield (filename, line, declarator, declspecs, width)
{
tree value;
+ if (declarator == NULL_TREE && width == NULL_TREE)
+ {
+ /* This is an unnamed decl. We only support unnamed
+ structs/unions, so check for other things and refuse them. */
+ if (TREE_CODE (TREE_VALUE (declspecs)) != RECORD_TYPE
+ && TREE_CODE (TREE_VALUE (declspecs)) != UNION_TYPE)
+ {
+ error ("unnamed fields of type other than struct or union are not allowed");
+ return NULL_TREE;
+ }
+ }
+
value = grokdeclarator (declarator, declspecs, width ? BITFIELD : FIELD, 0);
finish_decl (value, NULL_TREE, NULL_TREE);