* Make C1X anonymous structs/unions follow N1549
@ 2011-03-18 21:17 Joseph S. Myers
2011-03-18 21:52 ` Jakub Jelinek
0 siblings, 1 reply; 4+ messages in thread
From: Joseph S. Myers @ 2011-03-18 21:17 UTC (permalink / raw)
To: gcc-patches; +Cc: Mark Mitchell, jakub, rguenther
This week's London WG14 meeting agreed to disallow the use of typedefs
in declaring anonymous structure and union fields, as per N1549. This
patch implements this, restricting the use of typedefs in this case to
-fms-extensions and -fplan9-extensions as in 4.5 and earlier releases.
Bootstrapped with no regressions on x86_64-unknown-linux-gnu. Applied
to mainline. Any comments from other RMs about whether this should go
in 4.6 as well, to avoid 4.6.0 being more lenient in this area than
both 4.5 and 4.7? (The issue is about what is accepted by default
rather than -std=c1x, since -std=c1x users in 4.6 should know it's
experimental and subject to change.)
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.
testsuite:
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.
Index: doc/extend.texi
===================================================================
--- doc/extend.texi (revision 171110)
+++ doc/extend.texi (working copy)
@@ -13352,12 +13352,11 @@ The compiler gives errors for such const
@opindex fms-extensions
Unless @option{-fms-extensions} is used, the unnamed field must be a
structure or union definition without a tag (for example, @samp{struct
-@{ int a; @};}), or a @code{typedef} name for such a structure or
-union. If @option{-fms-extensions} is used, the field may
+@{ int a; @};}). If @option{-fms-extensions} is used, the field may
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
@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
The option @option{-fplan9-extensions} enables
Index: testsuite/gcc.dg/c1x-anon-struct-3.c
===================================================================
--- testsuite/gcc.dg/c1x-anon-struct-3.c (revision 0)
+++ testsuite/gcc.dg/c1x-anon-struct-3.c (revision 0)
@@ -0,0 +1,34 @@
+/* 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;
+ };
+};
Index: testsuite/gcc.dg/anon-struct-11.c
===================================================================
--- testsuite/gcc.dg/anon-struct-11.c (revision 171110)
+++ testsuite/gcc.dg/anon-struct-11.c (working copy)
@@ -50,7 +50,7 @@ struct E {
struct F { char f; }; /* { dg-warning "does not declare anything" } */
char c;
union {
- D;
+ D; /* { dg-warning "does not declare anything" } */
};
char e;
};
@@ -85,7 +85,7 @@ test2 (void)
e.e = 5;
f2 (&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 ();
if (e.f != 6) /* { dg-error "no member" } */
abort ();
Index: testsuite/gcc.dg/c1x-anon-struct-1.c
===================================================================
--- testsuite/gcc.dg/c1x-anon-struct-1.c (revision 171110)
+++ testsuite/gcc.dg/c1x-anon-struct-1.c (working copy)
@@ -4,20 +4,13 @@
#include <stddef.h>
-typedef struct
-{
- int i;
-} s0;
-
-typedef union
-{
- int i;
-} u0;
-
struct s1
{
int a;
- u0;
+ union
+ {
+ int i;
+ };
struct
{
int b;
@@ -27,7 +20,10 @@ struct s1
union u1
{
int b;
- s0;
+ struct
+ {
+ int i;
+ };
union
{
int c;
@@ -44,7 +40,10 @@ struct s2
struct s3
{
- u0;
+ union
+ {
+ int i;
+ };
};
struct s4
Index: c-decl.c
===================================================================
--- c-decl.c (revision 171110)
+++ c-decl.c (working copy)
@@ -6674,11 +6674,14 @@ grokfield (location_t loc,
|| TREE_CODE (type) == UNION_TYPE);
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)
ok = true;
- else if (TYPE_NAME (TYPE_MAIN_VARIANT (type)) == NULL)
+ else if (TYPE_NAME (type) == NULL)
ok = true;
else
ok = false;
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Make C1X anonymous structs/unions follow N1549
2011-03-18 21:17 Make C1X anonymous structs/unions follow N1549 Joseph S. Myers
@ 2011-03-18 21:52 ` Jakub Jelinek
2011-03-18 22:31 ` Mark Mitchell
2011-03-18 23:01 ` Joseph S. Myers
0 siblings, 2 replies; 4+ messages in thread
From: Jakub Jelinek @ 2011-03-18 21:52 UTC (permalink / raw)
To: Joseph S. Myers; +Cc: gcc-patches, Mark Mitchell, rguenther
On Fri, Mar 18, 2011 at 09:16:55PM +0000, Joseph S. Myers wrote:
> This week's London WG14 meeting agreed to disallow the use of typedefs
> in declaring anonymous structure and union fields, as per N1549. This
> patch implements this, restricting the use of typedefs in this case to
> -fms-extensions and -fplan9-extensions as in 4.5 and earlier releases.
If I understand it right, your patch restores the 4.5 code except for
-fplan9-extensions and with flag_iso not being checked.
I guess it is ok for 4.6.0 too.
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Make C1X anonymous structs/unions follow N1549
2011-03-18 21:52 ` Jakub Jelinek
@ 2011-03-18 22:31 ` Mark Mitchell
2011-03-18 23:01 ` Joseph S. Myers
1 sibling, 0 replies; 4+ messages in thread
From: Mark Mitchell @ 2011-03-18 22:31 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Joseph S. Myers, gcc-patches, rguenther
On 3/18/2011 2:52 PM, Jakub Jelinek wrote:
>> This week's London WG14 meeting agreed to disallow the use of typedefs
>> in declaring anonymous structure and union fields, as per N1549. This
>> patch implements this, restricting the use of typedefs in this case to
>> -fms-extensions and -fplan9-extensions as in 4.5 and earlier releases.
> I guess it is ok for 4.6.0 too.
I think avoiding the ping-pong in behavior between 4.5 and 4.7 is a good
call. So, I think the patch is OK for 4.6.
Thank you,
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Make C1X anonymous structs/unions follow N1549
2011-03-18 21:52 ` Jakub Jelinek
2011-03-18 22:31 ` Mark Mitchell
@ 2011-03-18 23:01 ` Joseph S. Myers
1 sibling, 0 replies; 4+ messages in thread
From: Joseph S. Myers @ 2011-03-18 23:01 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches, Mark Mitchell, rguenther
On Fri, 18 Mar 2011, Jakub Jelinek wrote:
> On Fri, Mar 18, 2011 at 09:16:55PM +0000, Joseph S. Myers wrote:
> > This week's London WG14 meeting agreed to disallow the use of typedefs
> > in declaring anonymous structure and union fields, as per N1549. This
> > patch implements this, restricting the use of typedefs in this case to
> > -fms-extensions and -fplan9-extensions as in 4.5 and earlier releases.
>
> If I understand it right, your patch restores the 4.5 code except for
> -fplan9-extensions and with flag_iso not being checked.
Yes, that's the intent of the grokfield changes in this patch. (All the
other front-end changes in 4.6 relating to anonymous structs and unions
are unaffected by this typedef change.)
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-03-18 23:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-18 21:17 Make C1X anonymous structs/unions follow N1549 Joseph S. Myers
2011-03-18 21:52 ` Jakub Jelinek
2011-03-18 22:31 ` Mark Mitchell
2011-03-18 23:01 ` Joseph S. Myers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).