This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR c/6660


Hi!

This patch fixes PR c/6660, a regression from 3.0.x.
I don't see any reasons why structs/unions should be allowed but typedefs
of structs/unions forbidden.
Ok to commit, assuming testing succeeds?
For branch too?

2002-05-27  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.

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

--- gcc/c-decl.c.jj	Tue May 21 20:18:57 2002
+++ gcc/c-decl.c	Mon May 27 14:26:42 2002
@@ -5591,8 +5591,11 @@ grokfield (filename, line, declarator, d
     {
       /* 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;
--- gcc/testsuite/gcc.dg/20020527-1.c.jj	Mon May 27 14:38:07 2002
+++ gcc/testsuite/gcc.dg/20020527-1.c	Mon May 27 14:37:06 2002
@@ -0,0 +1,53 @@
+/* PR c/6660
+   Test whether an unnamed field with user defined type - struct or union is
+   accepted.  */
+/* { dg-do compile } */
+
+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;
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]