r314054 - Correctly compute linkage for members of internal linkage classes.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 22 21:02:18 PDT 2017


Author: rsmith
Date: Fri Sep 22 21:02:17 2017
New Revision: 314054

URL: http://llvm.org/viewvc/llvm-project?rev=314054&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/test/CXX/basic/basic.link/p8.cpp

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=314054&r1=314053&r2=314054&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Fri Sep 22 21:02:17 2017
@@ -871,12 +871,11 @@ LinkageComputer::getLVForClassMember(con
 
   LinkageInfo classLV =
     getLVForDecl(cast<RecordDecl>(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

Modified: cfe/trunk/test/CXX/basic/basic.link/p8.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/basic/basic.link/p8.cpp?rev=314054&r1=314053&r2=314054&view=diff
==============================================================================
--- cfe/trunk/test/CXX/basic/basic.link/p8.cpp (original)
+++ cfe/trunk/test/CXX/basic/basic.link/p8.cpp Fri Sep 22 21:02:17 2017
@@ -67,3 +67,12 @@ void use_inline_vars() {
   defined_after_use = 2;
 }
 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;
+}




More information about the cfe-commits mailing list