jkorous updated this revision to Diff 143736. jkorous added a comment. Addressed comments + proposal for refactoring of the namespace-related logic.
https://reviews.llvm.org/D45884 Files: Sema/SemaDecl.cpp SemaCXX/anonymous-union-export.cpp SemaCXX/anonymous-union.cpp Index: SemaCXX/anonymous-union.cpp =================================================================== --- SemaCXX/anonymous-union.cpp +++ SemaCXX/anonymous-union.cpp @@ -80,6 +80,10 @@ float float_val; }; +extern "C++" { +union { }; // expected-error{{anonymous unions at namespace or global scope must be declared 'static'}} +} + static union { int int_val2; // expected-note{{previous definition is here}} float float_val2; Index: SemaCXX/anonymous-union-export.cpp =================================================================== --- /dev/null +++ SemaCXX/anonymous-union-export.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -std=c++17 -fmodules-ts -emit-obj -verify %s + +export module M; +export { + union { bool a; }; // expected-error{{anonymous unions at namespace or global scope must be declared 'static'}} +} Index: Sema/SemaDecl.cpp =================================================================== --- Sema/SemaDecl.cpp +++ Sema/SemaDecl.cpp @@ -4645,12 +4645,16 @@ unsigned DiagID; if (Record->isUnion()) { // C++ [class.union]p6: + // C++17 [class.union.anon]p2: // Anonymous unions declared in a named namespace or in the // global namespace shall be declared static. + + DeclContext *OwnerScope = Owner->getRedeclContext(); + if (DS.getStorageClassSpec() != DeclSpec::SCS_static && - (isa<TranslationUnitDecl>(Owner) || - (isa<NamespaceDecl>(Owner) && - cast<NamespaceDecl>(Owner)->getDeclName()))) { + (OwnerScope->isTranslationUnit() || + (OwnerScope->isNamespace() && + !cast<NamespaceDecl>(OwnerScope)->isAnonymousNamespace()))) { Diag(Record->getLocation(), diag::err_anonymous_union_not_static) << FixItHint::CreateInsertion(Record->getLocation(), "static ");
Index: SemaCXX/anonymous-union.cpp =================================================================== --- SemaCXX/anonymous-union.cpp +++ SemaCXX/anonymous-union.cpp @@ -80,6 +80,10 @@ float float_val; }; +extern "C++" { +union { }; // expected-error{{anonymous unions at namespace or global scope must be declared 'static'}} +} + static union { int int_val2; // expected-note{{previous definition is here}} float float_val2; Index: SemaCXX/anonymous-union-export.cpp =================================================================== --- /dev/null +++ SemaCXX/anonymous-union-export.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -std=c++17 -fmodules-ts -emit-obj -verify %s + +export module M; +export { + union { bool a; }; // expected-error{{anonymous unions at namespace or global scope must be declared 'static'}} +} Index: Sema/SemaDecl.cpp =================================================================== --- Sema/SemaDecl.cpp +++ Sema/SemaDecl.cpp @@ -4645,12 +4645,16 @@ unsigned DiagID; if (Record->isUnion()) { // C++ [class.union]p6: + // C++17 [class.union.anon]p2: // Anonymous unions declared in a named namespace or in the // global namespace shall be declared static. + + DeclContext *OwnerScope = Owner->getRedeclContext(); + if (DS.getStorageClassSpec() != DeclSpec::SCS_static && - (isa<TranslationUnitDecl>(Owner) || - (isa<NamespaceDecl>(Owner) && - cast<NamespaceDecl>(Owner)->getDeclName()))) { + (OwnerScope->isTranslationUnit() || + (OwnerScope->isNamespace() && + !cast<NamespaceDecl>(OwnerScope)->isAnonymousNamespace()))) { Diag(Record->getLocation(), diag::err_anonymous_union_not_static) << FixItHint::CreateInsertion(Record->getLocation(), "static ");
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits