Skip to content

Commit 057c82c

Browse files
committed
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
1 parent ad92342 commit 057c82c

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

clang/include/clang/Basic/Visibility.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class LinkageInfo {
7575
static LinkageInfo none() {
7676
return LinkageInfo(NoLinkage, DefaultVisibility, false);
7777
}
78+
static LinkageInfo visible_none() {
79+
return LinkageInfo(VisibleNoLinkage, DefaultVisibility, false);
80+
}
7881

7982
Linkage getLinkage() const { return (Linkage)linkage_; }
8083
Visibility getVisibility() const { return (Visibility)visibility_; }

clang/include/clang/Sema/Lookup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class LookupResult {
275275
/// declarations, such as those in modules that have not yet been imported.
276276
bool isHiddenDeclarationVisible(NamedDecl *ND) const {
277277
return AllowHidden ||
278-
(isForRedeclaration() && ND->isExternallyVisible());
278+
(isForRedeclaration() && ND->hasExternalFormalLinkage());
279279
}
280280

281281
/// Sets whether tag declarations should be hidden by non-tag

clang/lib/AST/Decl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,9 @@ static LinkageInfo computeLVForDecl(const NamedDecl *D,
12511251

12521252
case Decl::EnumConstant:
12531253
// C++ [basic.link]p4: an enumerator has the linkage of its enumeration.
1254-
return getLVForDecl(cast<EnumDecl>(D->getDeclContext()), computation);
1254+
if (D->getASTContext().getLangOpts().CPlusPlus)
1255+
return getLVForDecl(cast<EnumDecl>(D->getDeclContext()), computation);
1256+
return LinkageInfo::visible_none();
12551257

12561258
case Decl::Typedef:
12571259
case Decl::TypeAlias:

clang/test/Index/linkage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void f16(void) {
2020

2121

2222
// CHECK: EnumDecl=Baz:3:6 (Definition)linkage=External
23-
// CHECK: EnumConstantDecl=Qux:3:12 (Definition)linkage=External
23+
// CHECK: EnumConstantDecl=Qux:3:12 (Definition)linkage=NoLinkage
2424
// CHECK: VarDecl=x:4:5linkage=External
2525
// CHECK: FunctionDecl=foo:5:6linkage=External
2626
// CHECK: VarDecl=w:6:12linkage=Internal

0 commit comments

Comments
 (0)