Fix linkage computation for local types in template functions.

Template functions (and member functions of class templates) present the same
problem as inline functions. They need to be uniqued, so we need to assign
VisibleNoLinkage linkage to types defined in them.

llvm-svn: 183222
This commit is contained in:
Rafael Espindola 2013-06-04 13:43:35 +00:00
parent 53c8c13bf1
commit 5218936310
2 changed files with 30 additions and 1 deletions

View File

@ -1049,8 +1049,12 @@ static LinkageInfo getLVForLocalDecl(const NamedDecl *D,
return LinkageInfo::none();
const FunctionDecl *FD = getOutermostFunctionContext(D);
if (!FD || !FD->isInlined())
if (!FD)
return LinkageInfo::none();
if (!FD->isInlined() && FD->getTemplateSpecializationKind() == TSK_Undeclared)
return LinkageInfo::none();
LinkageInfo LV = getLVForDecl(FD, computation);
if (!isExternallyVisible(LV.getLinkage()))
return LinkageInfo::none();

View File

@ -184,3 +184,28 @@ namespace test14 {
}
void h() { f(); }
}
namespace test15 {
// CHECK-DAG: define linkonce_odr void @_ZN6test153zedIZNS_3fooIiEEPvvE3bar_9EEvv(
template <class T> void zed() {}
template <class T> void *foo() {
class bar {
};
return reinterpret_cast<void *>(zed<bar>);
}
void test() { foo<int>(); }
}
namespace test16 {
// CHECK-DAG: define linkonce_odr void @_ZN6test163zedIZNS_3fooIiE3barEvE1S__10_EEvv(
template <class T> void zed() {}
template <class T> struct foo {
static void *bar();
};
template <class T> void *foo<T>::bar() {
class S {
};
return reinterpret_cast<void *>(zed<S>);
}
void *test() { return foo<int>::bar(); }
}