On Sun, Jan 27, 2013 at 7:23 PM, NAKAMURA Takumi <span dir="ltr"><<a href="mailto:geek4civic@gmail.com" target="_blank">geek4civic@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Richard, it brought many warnings on the tree.<br>
<a href="http://bb.pgr.jp/builders/clang-3stage-x86_64-linux/builds/846" target="_blank">http://bb.pgr.jp/builders/clang-3stage-x86_64-linux/builds/846</a><br>
<br>
What could we do? Fix extensions, or ... ?<br></blockquote><div><br></div><div>Maybe we should just turn the warning off for LLVM and Clang; this is a widely-available language extension which apparently no-one even noticed that we were using by accident. That said, the very first case where it fires looks like a pretty egregious violation of the rules.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
...Takumi<br>
<br>
2013/1/28 Richard Smith <<a href="mailto:richard-llvm@metafoo.co.uk">richard-llvm@metafoo.co.uk</a>>:<br>
<div class="HOEnZb"><div class="h5">> Author: rsmith<br>
> Date: Sun Jan 27 18:54:05 2013<br>
> New Revision: 173643<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=173643&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=173643&view=rev</a><br>
> Log:<br>
> Add a -pedantic warning: an anonymous union within an anonymous union is not<br>
> permitted in standard C++, despite being silently accepted by many (all?) major<br>
> C++ implementations.<br>
><br>
> Modified:<br>
>     cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
>     cfe/trunk/lib/Sema/SemaDecl.cpp<br>
>     cfe/trunk/test/SemaCXX/anonymous-union.cpp<br>
>     cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp<br>
><br>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=173643&r1=173642&r2=173643&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=173643&r1=173642&r2=173643&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)<br>
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Jan 27 18:54:05 2013<br>
> @@ -5344,6 +5344,9 @@ def err_anonymous_record_with_type : Err<br>
>  def ext_anonymous_record_with_type : Extension<<br>
>    "types declared in an anonymous %select{struct|union}0 are a Microsoft "<br>
>    "extension">, InGroup<Microsoft>;<br>
> +def ext_anonymous_record_with_anonymous_type : Extension<<br>
> +  "nested anonymous types are an extension">,<br>
> +  InGroup<DiagGroup<"nested-anon-types">>;<br>
>  def err_anonymous_record_with_function : Error<<br>
>    "functions cannot be declared in an anonymous %select{struct|union}0">;<br>
>  def err_anonymous_record_with_static : Error<<br>
><br>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=173643&r1=173642&r2=173643&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=173643&r1=173642&r2=173643&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)<br>
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Jan 27 18:54:05 2013<br>
> @@ -3198,6 +3198,12 @@ Decl *Sema::BuildAnonymousStructOrUnion(<br>
>                << (int)Record->isUnion();<br>
>              Invalid = true;<br>
>            }<br>
> +        } else {<br>
> +          // This is an anonymous type definition within another anonymous type.<br>
> +          // This is a popular extension, provided by Plan9, MSVC and GCC, but<br>
> +          // not part of standard C++.<br>
> +          Diag(MemRecord->getLocation(),<br>
> +               diag::ext_anonymous_record_with_anonymous_type);<br>
>          }<br>
>        } else if (isa<AccessSpecDecl>(*Mem)) {<br>
>          // Any access specifier is fine.<br>
><br>
> Modified: cfe/trunk/test/SemaCXX/anonymous-union.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/anonymous-union.cpp?rev=173643&r1=173642&r2=173643&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/anonymous-union.cpp?rev=173643&r1=173642&r2=173643&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/test/SemaCXX/anonymous-union.cpp (original)<br>
> +++ cfe/trunk/test/SemaCXX/anonymous-union.cpp Sun Jan 27 18:54:05 2013<br>
> @@ -9,7 +9,7 @@ struct X {<br>
>      int i;<br>
>      float f;<br>
><br>
> -    union {<br>
> +    union { // expected-warning{{nested anonymous types are an extension}}<br>
>        float f2;<br>
>        mutable double d;<br>
>      };<br>
> @@ -101,7 +101,7 @@ void g() {<br>
>  struct BadMembers {<br>
>    union {<br>
>      struct X { }; // expected-error {{types cannot be declared in an anonymous union}}<br>
> -    struct { int x; int y; } y;<br>
> +    struct { int x; int y; } y; // expected-warning{{nested anonymous types are an extension}}<br>
><br>
>      void f(); // expected-error{{functions cannot be declared in an anonymous union}}<br>
>    private: int x1; // expected-error{{anonymous union cannot contain a private data member}}<br>
> @@ -128,7 +128,7 @@ namespace test4 {<br>
>      struct { // expected-warning{{anonymous structs are a GNU extension}}<br>
>        int s0; // expected-note {{declared private here}}<br>
>        double s1; // expected-note {{declared private here}}<br>
> -      union {<br>
> +      union { // expected-warning{{nested anonymous type}}<br>
>          int su0; // expected-note {{declared private here}}<br>
>          double su1; // expected-note {{declared private here}}<br>
>        };<br>
> @@ -136,7 +136,7 @@ namespace test4 {<br>
>      union {<br>
>        int u0; // expected-note {{declared private here}}<br>
>        double u1; // expected-note {{declared private here}}<br>
> -      struct { // expected-warning{{anonymous structs are a GNU extension}}<br>
> +      struct { // expected-warning{{anonymous structs are a GNU extension}} expected-warning{{nested anonymous type}}<br>
>          int us0; // expected-note {{declared private here}}<br>
>          double us1; // expected-note {{declared private here}}<br>
>        };<br>
> @@ -187,7 +187,7 @@ namespace PR8326 {<br>
><br>
>    private:<br>
>      const union { // expected-warning{{anonymous union cannot be 'const'}}<br>
> -      struct { // expected-warning{{anonymous structs are a GNU extension}}<br>
> +      struct { // expected-warning{{anonymous structs are a GNU extension}} expected-warning{{nested anonymous type}}<br>
>          T x;<br>
>          T y;<br>
>        };<br>
><br>
> Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=173643&r1=173642&r2=173643&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=173643&r1=173642&r2=173643&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)<br>
> +++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Sun Jan 27 18:54:05 2013<br>
> @@ -1153,8 +1153,8 @@ namespace ConvertedConstantExpr {<br>
>  namespace IndirectField {<br>
>    struct S {<br>
>      struct { // expected-warning {{GNU extension}}<br>
> -      union {<br>
> -        struct { // expected-warning {{GNU extension}}<br>
> +      union { // expected-warning {{nested anonymous types are an extension}}<br>
> +        struct { // expected-warning {{GNU extension}} expected-warning {{nested anonymous types are an extension}}<br>
>            int a;<br>
>            int b;<br>
>          };<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br>