diff options
author | Bruno Cardoso Lopes <bruno.cardoso@gmail.com> | 2017-07-01 00:06:27 +0000 |
---|---|---|
committer | Bruno Cardoso Lopes <bruno.cardoso@gmail.com> | 2017-07-01 00:06:27 +0000 |
commit | 057c82cf25a0c8bd4150eb715310b1d74a538aac (patch) | |
tree | 34cd387011d23fc2b37f27f53b6435a3866412f2 | |
parent | ad923425ac3e79e4b9722fcd9df3141b597314b7 (diff) | |
download | bcm5719-llvm-057c82cf25a0c8bd4150eb715310b1d74a538aac.tar.gz bcm5719-llvm-057c82cf25a0c8bd4150eb715310b1d74a538aac.zip |
Change enumerator default linkage type for C
Redeclaration lookup should never find hidden enumerators in C, because
they do not have linkage (C11 6.2.2/6)
The linkage of an enumerator should be VisibleNoLinkage, and
isHiddenDeclarationVisible should be checking hasExternalFormalLinkage.
This is was reviewed as part of D31778, but splitted into a different
commit for clarity.
rdar://problem/31909368
llvm-svn: 306917
-rw-r--r-- | clang/include/clang/Basic/Visibility.h | 3 | ||||
-rw-r--r-- | clang/include/clang/Sema/Lookup.h | 2 | ||||
-rw-r--r-- | clang/lib/AST/Decl.cpp | 4 | ||||
-rw-r--r-- | clang/test/Index/linkage.c | 2 |
4 files changed, 8 insertions, 3 deletions
diff --git a/clang/include/clang/Basic/Visibility.h b/clang/include/clang/Basic/Visibility.h index 6ac52ed6b5e..cc839d789e7 100644 --- a/clang/include/clang/Basic/Visibility.h +++ b/clang/include/clang/Basic/Visibility.h @@ -75,6 +75,9 @@ public: static LinkageInfo none() { return LinkageInfo(NoLinkage, DefaultVisibility, false); } + static LinkageInfo visible_none() { + return LinkageInfo(VisibleNoLinkage, DefaultVisibility, false); + } Linkage getLinkage() const { return (Linkage)linkage_; } Visibility getVisibility() const { return (Visibility)visibility_; } diff --git a/clang/include/clang/Sema/Lookup.h b/clang/include/clang/Sema/Lookup.h index fc16ad2e819..ea32997d406 100644 --- a/clang/include/clang/Sema/Lookup.h +++ b/clang/include/clang/Sema/Lookup.h @@ -275,7 +275,7 @@ public: /// declarations, such as those in modules that have not yet been imported. bool isHiddenDeclarationVisible(NamedDecl *ND) const { return AllowHidden || - (isForRedeclaration() && ND->isExternallyVisible()); + (isForRedeclaration() && ND->hasExternalFormalLinkage()); } /// Sets whether tag declarations should be hidden by non-tag diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 8677b1155a6..267c6992af8 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -1251,7 +1251,9 @@ static LinkageInfo computeLVForDecl(const NamedDecl *D, case Decl::EnumConstant: // C++ [basic.link]p4: an enumerator has the linkage of its enumeration. - return getLVForDecl(cast<EnumDecl>(D->getDeclContext()), computation); + if (D->getASTContext().getLangOpts().CPlusPlus) + return getLVForDecl(cast<EnumDecl>(D->getDeclContext()), computation); + return LinkageInfo::visible_none(); case Decl::Typedef: case Decl::TypeAlias: diff --git a/clang/test/Index/linkage.c b/clang/test/Index/linkage.c index ab006590b61..b0dcb30990a 100644 --- a/clang/test/Index/linkage.c +++ b/clang/test/Index/linkage.c @@ -20,7 +20,7 @@ void f16(void) { // CHECK: EnumDecl=Baz:3:6 (Definition)linkage=External -// CHECK: EnumConstantDecl=Qux:3:12 (Definition)linkage=External +// CHECK: EnumConstantDecl=Qux:3:12 (Definition)linkage=NoLinkage // CHECK: VarDecl=x:4:5linkage=External // CHECK: FunctionDecl=foo:5:6linkage=External // CHECK: VarDecl=w:6:12linkage=Internal |