diff options
author | Jan Korous <jkorous@apple.com> | 2018-06-06 05:16:34 +0000 |
---|---|---|
committer | Jan Korous <jkorous@apple.com> | 2018-06-06 05:16:34 +0000 |
commit | 86869aa106eeea261d088f20479c15939675e0c4 (patch) | |
tree | 7c7380ba2bc3e04b2303ae501b0b11d0c5c9f52b /lib/Sema/SemaDecl.cpp | |
parent | 061e488871f28e55b8b3da15c88617b7fa08a541 (diff) | |
download | clang-86869aa106eeea261d088f20479c15939675e0c4.tar.gz |
[Sema] Fix parsing of anonymous union in language linkage specification
C++17 [dcl.link]p4:
A linkage specification does not establish a scope.
C++17 [class.union.anon]p2:
Namespace level anonymous unions shall be declared static.
Differential Revision: https://reviews.llvm.org/D45884
rdar://problem/37545925
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@334062 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 862da62149..e1ee8ec079 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4642,12 +4642,14 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, 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 "); |