re PR c/6660 (Typedeffed unnamed structs/unions do not compile with gcc-3.1)
authorJakub Jelinek <jakub@redhat.com>
Mon, 10 Jun 2002 21:52:43 +0000 (23:52 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 10 Jun 2002 21:52:43 +0000 (23:52 +0200)
PR c/6660
* c-decl.c (grokfield): Allow user defined types if they declare
structs or unions for unnamed fields.

* gcc.dg/20020527-1.c: New test.

From-SVN: r54466

gcc/ChangeLog
gcc/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/20020527-1.c [new file with mode: 0644]

index 347b5bacc13def148f691b0dc98b63f38c1a4020..f92ef9b762c598c328c22475fcc2d344671b1479 100644 (file)
@@ -1,3 +1,9 @@
+2002-06-10  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/6660
+       * c-decl.c (grokfield): Allow user defined types if they declare
+       structs or unions for unnamed fields.
+
 2002-06-10  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/6809
index 819e26e95961e39bee160c21d56357daee6c9e94..075ac6d0bb0a33042e3f487d0c0f53a6d49fc734 100644 (file)
@@ -5361,8 +5361,11 @@ grokfield (filename, line, declarator, declspecs, width)
     {
       /* 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)
+      tree type = TREE_VALUE (declspecs);
+
+      if (TREE_CODE (type) == TYPE_DECL)
+       type = TREE_TYPE (type);
+      if (TREE_CODE (type) != RECORD_TYPE && TREE_CODE (type) != UNION_TYPE)
        {
          error ("unnamed fields of type other than struct or union are not allowed");
          return NULL_TREE;
index 91db3bc36ab0c1ac512d80eb59cad875be367a3e..1d8229c615e178e5a9a31913c09b405f3e7a8ec1 100644 (file)
@@ -8,6 +8,8 @@
 
        * gcc.dg/20020530-1.c: New test.
 
+       * gcc.dg/20020527-1.c: New test.
+
 2002-06-07  Roger Sayle  <roger@eyesopen.com>
 
        * gcc.dg/20020607-2.c: New test case.
diff --git a/gcc/testsuite/gcc.dg/20020527-1.c b/gcc/testsuite/gcc.dg/20020527-1.c
new file mode 100644 (file)
index 0000000..f480d7b
--- /dev/null
@@ -0,0 +1,54 @@
+/* PR c/6660
+   Test whether an unnamed field with user defined type - struct or union is
+   accepted.  */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+typedef struct {
+  unsigned short a;
+  unsigned short b;
+} __attribute__ ((__packed__)) A;
+
+typedef struct B_ {
+  unsigned int c;
+  unsigned int d;
+} B;
+
+typedef struct C_ {
+  B;
+  unsigned int e;
+  unsigned int f;
+} C;
+
+typedef C D;
+
+typedef struct {
+  A;
+  D;
+  struct {
+    unsigned short g;
+    unsigned short h;
+  } __attribute__ ((__packed__));
+  union {
+    int i;
+    long j;
+  };
+  int k;
+} __attribute__ ((__packed__)) E;
+
+E x;
+
+void foo (void)
+{
+  x.a = 1;
+  x.b = 2;
+  x.c = 3;
+  x.d = 4;
+  x.e = 5;
+  x.f = 6;
+  x.g = 7;
+  x.h = 8;
+  x.i = 9;
+  x.j = 10;
+  x.k = 11;
+}