Commit ff8e2159 by Joseph Myers Committed by Joseph Myers

c-decl.c (grokfield): Don't allow typedefs for structures or unions with no tag by default.

	* c-decl.c (grokfield): Don't allow typedefs for structures or
	unions with no tag by default.
	* doc/extend.texi (Unnamed Fields): Update.

testsuite:
	* gcc.dg/c1x-anon-struct-1.c: Don't test use of typedefs.
	* gcc.dg/c1x-anon-struct-3.c: New test.
	* gcc.dg/anon-struct-11.c: Update.

From-SVN: r171170
parent 16cc4440
2011-03-18 Joseph Myers <joseph@codesourcery.com>
* c-decl.c (grokfield): Don't allow typedefs for structures or
unions with no tag by default.
* doc/extend.texi (Unnamed Fields): Update.
2011-03-18 Uros Bizjak <ubizjak@gmail.com> 2011-03-18 Uros Bizjak <ubizjak@gmail.com>
* config/i386/i386.md (float<SSEMODEI24:mode><X87MODEF:mode>2): * config/i386/i386.md (float<SSEMODEI24:mode><X87MODEF:mode>2):
......
...@@ -6674,11 +6674,14 @@ grokfield (location_t loc, ...@@ -6674,11 +6674,14 @@ grokfield (location_t loc,
|| TREE_CODE (type) == UNION_TYPE); || TREE_CODE (type) == UNION_TYPE);
bool ok = false; bool ok = false;
if (type_ok) if (type_ok
&& (flag_ms_extensions
|| flag_plan9_extensions
|| !declspecs->typedef_p))
{ {
if (flag_ms_extensions || flag_plan9_extensions) if (flag_ms_extensions || flag_plan9_extensions)
ok = true; ok = true;
else if (TYPE_NAME (TYPE_MAIN_VARIANT (type)) == NULL) else if (TYPE_NAME (type) == NULL)
ok = true; ok = true;
else else
ok = false; ok = false;
......
...@@ -13352,12 +13352,11 @@ The compiler gives errors for such constructs. ...@@ -13352,12 +13352,11 @@ The compiler gives errors for such constructs.
@opindex fms-extensions @opindex fms-extensions
Unless @option{-fms-extensions} is used, the unnamed field must be a Unless @option{-fms-extensions} is used, the unnamed field must be a
structure or union definition without a tag (for example, @samp{struct structure or union definition without a tag (for example, @samp{struct
@{ int a; @};}), or a @code{typedef} name for such a structure or @{ int a; @};}). If @option{-fms-extensions} is used, the field may
union. If @option{-fms-extensions} is used, the field may
also be a definition with a tag such as @samp{struct foo @{ int a; also be a definition with a tag such as @samp{struct foo @{ int a;
@};}, a reference to a previously defined structure or union such as @};}, a reference to a previously defined structure or union such as
@samp{struct foo;}, or a reference to a @code{typedef} name for a @samp{struct foo;}, or a reference to a @code{typedef} name for a
previously defined structure or union type with a tag. previously defined structure or union type.
@opindex fplan9-extensions @opindex fplan9-extensions
The option @option{-fplan9-extensions} enables The option @option{-fplan9-extensions} enables
......
2011-03-18 Joseph Myers <joseph@codesourcery.com>
* gcc.dg/c1x-anon-struct-1.c: Don't test use of typedefs.
* gcc.dg/c1x-anon-struct-3.c: New test.
* gcc.dg/anon-struct-11.c: Update.
2011-03-18 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> 2011-03-18 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
* gcc.dg/vect/slp-multitypes-2.c: Replace dg-do run with * gcc.dg/vect/slp-multitypes-2.c: Replace dg-do run with
......
...@@ -50,7 +50,7 @@ struct E { ...@@ -50,7 +50,7 @@ struct E {
struct F { char f; }; /* { dg-warning "does not declare anything" } */ struct F { char f; }; /* { dg-warning "does not declare anything" } */
char c; char c;
union { union {
D; D; /* { dg-warning "does not declare anything" } */
}; };
char e; char e;
}; };
...@@ -85,7 +85,7 @@ test2 (void) ...@@ -85,7 +85,7 @@ test2 (void)
e.e = 5; e.e = 5;
f2 (&e); /* { dg-warning "incompatible pointer type" } */ f2 (&e); /* { dg-warning "incompatible pointer type" } */
f3 (&e); /* { dg-warning "incompatible pointer type" } */ f3 (&e); /* { dg-warning "incompatible pointer type" } */
if (e.d != 4) if (e.d != 4) /* { dg-error "no member" } */
abort (); abort ();
if (e.f != 6) /* { dg-error "no member" } */ if (e.f != 6) /* { dg-error "no member" } */
abort (); abort ();
......
...@@ -4,20 +4,13 @@ ...@@ -4,20 +4,13 @@
#include <stddef.h> #include <stddef.h>
typedef struct
{
int i;
} s0;
typedef union
{
int i;
} u0;
struct s1 struct s1
{ {
int a; int a;
u0; union
{
int i;
};
struct struct
{ {
int b; int b;
...@@ -27,7 +20,10 @@ struct s1 ...@@ -27,7 +20,10 @@ struct s1
union u1 union u1
{ {
int b; int b;
s0; struct
{
int i;
};
union union
{ {
int c; int c;
...@@ -44,7 +40,10 @@ struct s2 ...@@ -44,7 +40,10 @@ struct s2
struct s3 struct s3
{ {
u0; union
{
int i;
};
}; };
struct s4 struct s4
......
/* Test for anonymous structures and unions in C1X. Test for invalid
cases: typedefs disallowed by N1549. */
/* { dg-do compile } */
/* { dg-options "-std=c1x -pedantic-errors" } */
typedef struct
{
int i;
} s0;
typedef union
{
int i;
} u0;
struct s1
{
int a;
u0; /* { dg-error "declaration does not declare anything" } */
struct
{
int b;
};
};
union u1
{
int b;
s0; /* { dg-error "declaration does not declare anything" } */
union
{
int c;
};
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment