re PR c/6660 (Typedeffed unnamed structs/unions do not compile with gcc-3.1)

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
This commit is contained in:
Jakub Jelinek 2002-06-10 23:52:43 +02:00 committed by Jakub Jelinek
parent 50f30e6b07
commit 85d490584b
4 changed files with 67 additions and 2 deletions

View 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

View 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;

View 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.

View File

@ -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;
}