]> granicus.if.org Git - clang/commitdiff
Change enumerator default linkage type for C
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Sat, 1 Jul 2017 00:06:27 +0000 (00:06 +0000)
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Sat, 1 Jul 2017 00:06:27 +0000 (00:06 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306917 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Visibility.h
include/clang/Sema/Lookup.h
lib/AST/Decl.cpp
test/Index/linkage.c

index 6ac52ed6b5e1d8fc106ba4d689dbd6d4af69a851..cc839d789e7fd8d2160f94fbb778e1b709a0315d 100644 (file)
@@ -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_; }
index fc16ad2e819e8591e1820e6d061a0f937258f582..ea32997d4066793a59b52dc53a25f63b9ba11fc1 100644 (file)
@@ -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
index 8677b1155a606174919ea4ec40d022fa1e87db85..267c6992af89784ed0c3ba2f6eedbded401f8de2 100644 (file)
@@ -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:
index ab006590b61c0992694d1b23fdb6bfb2302df6cf..b0dcb30990a02fb028831d34bdc7a8607b4d4526 100644 (file)
@@ -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