On Sun, Jan 27, 2013 at 7:23 PM, NAKAMURA Takumi <[email protected]>wrote:
> Richard, it brought many warnings on the tree. > http://bb.pgr.jp/builders/clang-3stage-x86_64-linux/builds/846 > > What could we do? Fix extensions, or ... ? > 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. > ...Takumi > > 2013/1/28 Richard Smith <[email protected]>: > > Author: rsmith > > Date: Sun Jan 27 18:54:05 2013 > > New Revision: 173643 > > > > URL: http://llvm.org/viewvc/llvm-project?rev=173643&view=rev > > Log: > > Add a -pedantic warning: an anonymous union within an anonymous union is > not > > permitted in standard C++, despite being silently accepted by many > (all?) major > > C++ implementations. > > > > Modified: > > cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td > > cfe/trunk/lib/Sema/SemaDecl.cpp > > cfe/trunk/test/SemaCXX/anonymous-union.cpp > > cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp > > > > Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td > > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=173643&r1=173642&r2=173643&view=diff > > > ============================================================================== > > --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) > > +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Jan 27 > 18:54:05 2013 > > @@ -5344,6 +5344,9 @@ def err_anonymous_record_with_type : Err > > def ext_anonymous_record_with_type : Extension< > > "types declared in an anonymous %select{struct|union}0 are a > Microsoft " > > "extension">, InGroup<Microsoft>; > > +def ext_anonymous_record_with_anonymous_type : Extension< > > + "nested anonymous types are an extension">, > > + InGroup<DiagGroup<"nested-anon-types">>; > > def err_anonymous_record_with_function : Error< > > "functions cannot be declared in an anonymous > %select{struct|union}0">; > > def err_anonymous_record_with_static : Error< > > > > Modified: cfe/trunk/lib/Sema/SemaDecl.cpp > > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=173643&r1=173642&r2=173643&view=diff > > > ============================================================================== > > --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) > > +++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Jan 27 18:54:05 2013 > > @@ -3198,6 +3198,12 @@ Decl *Sema::BuildAnonymousStructOrUnion( > > << (int)Record->isUnion(); > > Invalid = true; > > } > > + } else { > > + // This is an anonymous type definition within another > anonymous type. > > + // This is a popular extension, provided by Plan9, MSVC and > GCC, but > > + // not part of standard C++. > > + Diag(MemRecord->getLocation(), > > + diag::ext_anonymous_record_with_anonymous_type); > > } > > } else if (isa<AccessSpecDecl>(*Mem)) { > > // Any access specifier is fine. > > > > Modified: cfe/trunk/test/SemaCXX/anonymous-union.cpp > > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/anonymous-union.cpp?rev=173643&r1=173642&r2=173643&view=diff > > > ============================================================================== > > --- cfe/trunk/test/SemaCXX/anonymous-union.cpp (original) > > +++ cfe/trunk/test/SemaCXX/anonymous-union.cpp Sun Jan 27 18:54:05 2013 > > @@ -9,7 +9,7 @@ struct X { > > int i; > > float f; > > > > - union { > > + union { // expected-warning{{nested anonymous types are an > extension}} > > float f2; > > mutable double d; > > }; > > @@ -101,7 +101,7 @@ void g() { > > struct BadMembers { > > union { > > struct X { }; // expected-error {{types cannot be declared in an > anonymous union}} > > - struct { int x; int y; } y; > > + struct { int x; int y; } y; // expected-warning{{nested anonymous > types are an extension}} > > > > void f(); // expected-error{{functions cannot be declared in an > anonymous union}} > > private: int x1; // expected-error{{anonymous union cannot contain a > private data member}} > > @@ -128,7 +128,7 @@ namespace test4 { > > struct { // expected-warning{{anonymous structs are a GNU > extension}} > > int s0; // expected-note {{declared private here}} > > double s1; // expected-note {{declared private here}} > > - union { > > + union { // expected-warning{{nested anonymous type}} > > int su0; // expected-note {{declared private here}} > > double su1; // expected-note {{declared private here}} > > }; > > @@ -136,7 +136,7 @@ namespace test4 { > > union { > > int u0; // expected-note {{declared private here}} > > double u1; // expected-note {{declared private here}} > > - struct { // expected-warning{{anonymous structs are a GNU > extension}} > > + struct { // expected-warning{{anonymous structs are a GNU > extension}} expected-warning{{nested anonymous type}} > > int us0; // expected-note {{declared private here}} > > double us1; // expected-note {{declared private here}} > > }; > > @@ -187,7 +187,7 @@ namespace PR8326 { > > > > private: > > const union { // expected-warning{{anonymous union cannot be > 'const'}} > > - struct { // expected-warning{{anonymous structs are a GNU > extension}} > > + struct { // expected-warning{{anonymous structs are a GNU > extension}} expected-warning{{nested anonymous type}} > > T x; > > T y; > > }; > > > > Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp > > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=173643&r1=173642&r2=173643&view=diff > > > ============================================================================== > > --- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original) > > +++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Sun Jan 27 > 18:54:05 2013 > > @@ -1153,8 +1153,8 @@ namespace ConvertedConstantExpr { > > namespace IndirectField { > > struct S { > > struct { // expected-warning {{GNU extension}} > > - union { > > - struct { // expected-warning {{GNU extension}} > > + union { // expected-warning {{nested anonymous types are an > extension}} > > + struct { // expected-warning {{GNU extension}} expected-warning > {{nested anonymous types are an extension}} > > int a; > > int b; > > }; > > > > > > _______________________________________________ > > cfe-commits mailing list > > [email protected] > > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
