From 2e4086bb2d8b007a7232fae27e6068a83c2433fd Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sat, 23 Sep 2017 04:02:17 +0000 Subject: [PATCH] Correctly compute linkage for members of internal linkage classes. We used to give such members no linkage instead of giving them the linkage of the class. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314054 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Decl.cpp | 9 ++++----- test/CXX/basic/basic.link/p8.cpp | 9 +++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 3f9eaf28ef..f77345f9c2 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -871,12 +871,11 @@ LinkageComputer::getLVForClassMember(const NamedDecl *D, LinkageInfo classLV = getLVForDecl(cast(D->getDeclContext()), classComputation); - // If the class already has unique-external linkage, we can't improve. - if (classLV.getLinkage() == UniqueExternalLinkage) - return LinkageInfo::uniqueExternal(); - + // The member has the same linkage as the class. If that's not externally + // visible, we don't need to compute anything about the linkage. + // FIXME: If we're only computing linkage, can we bail out here? if (!isExternallyVisible(classLV.getLinkage())) - return LinkageInfo::none(); + return classLV; // Otherwise, don't merge in classLV yet, because in certain cases diff --git a/test/CXX/basic/basic.link/p8.cpp b/test/CXX/basic/basic.link/p8.cpp index 317fb31fb0..54b977d77f 100644 --- a/test/CXX/basic/basic.link/p8.cpp +++ b/test/CXX/basic/basic.link/p8.cpp @@ -67,3 +67,12 @@ void use_inline_vars() { defined_after_use = 2; } inline int defined_after_use; + +namespace { + template struct A { + static const int n; + }; + template const int A::n = 3; + static_assert(A::n == 3); + int k = A::n; +} -- 2.40.0