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.

llvm-svn: 314054
This commit is contained in:
Richard Smith 2017-09-23 04:02:17 +00:00
parent 5b81dfc76e
commit cdb06f2150
2 changed files with 13 additions and 5 deletions

View File

@ -871,12 +871,11 @@ LinkageComputer::getLVForClassMember(const NamedDecl *D,
LinkageInfo classLV = LinkageInfo classLV =
getLVForDecl(cast<RecordDecl>(D->getDeclContext()), classComputation); getLVForDecl(cast<RecordDecl>(D->getDeclContext()), classComputation);
// If the class already has unique-external linkage, we can't improve. // The member has the same linkage as the class. If that's not externally
if (classLV.getLinkage() == UniqueExternalLinkage) // visible, we don't need to compute anything about the linkage.
return LinkageInfo::uniqueExternal(); // FIXME: If we're only computing linkage, can we bail out here?
if (!isExternallyVisible(classLV.getLinkage())) if (!isExternallyVisible(classLV.getLinkage()))
return LinkageInfo::none(); return classLV;
// Otherwise, don't merge in classLV yet, because in certain cases // Otherwise, don't merge in classLV yet, because in certain cases

View File

@ -67,3 +67,12 @@ void use_inline_vars() {
defined_after_use = 2; defined_after_use = 2;
} }
inline int defined_after_use; inline int defined_after_use;
namespace {
template<typename T> struct A {
static const int n;
};
template<typename T> const int A<T>::n = 3;
static_assert(A<int>::n == 3);
int k = A<float>::n;
}