A C++ member function always has either weak linkage (if it's inline or defined inline) or strong linkage (other cases).

llvm-svn: 71873
This commit is contained in:
Anders Carlsson 2009-05-15 18:35:39 +00:00
parent 82049e6bdd
commit 37604a0984
2 changed files with 16 additions and 1 deletions

View File

@ -241,6 +241,14 @@ void CodeGenModule::EmitAnnotations() {
static CodeGenModule::GVALinkage static CodeGenModule::GVALinkage
GetLinkageForFunction(const FunctionDecl *FD, const LangOptions &Features) { GetLinkageForFunction(const FunctionDecl *FD, const LangOptions &Features) {
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
// C++ member functions defined inside the class are always inline.
if (MD->isInline() || !MD->isOutOfLineDefinition())
return CodeGenModule::GVA_CXXInline;
return CodeGenModule::GVA_StrongExternal;
}
// "static" functions get internal linkage. // "static" functions get internal linkage.
if (FD->getStorageClass() == FunctionDecl::Static) if (FD->getStorageClass() == FunctionDecl::Static)
return CodeGenModule::GVA_Internal; return CodeGenModule::GVA_Internal;

View File

@ -26,14 +26,21 @@ struct S {
inline ~S() { } inline ~S() { }
// RUN: grep "define linkonce_odr void @_ZN1S9f_inline1Ev" %t &&
void f_inline1() { } void f_inline1() { }
// RUN: grep "define linkonce_odr void @_ZN1S9f_inline2Ev" %t && // RUN: grep "define linkonce_odr void @_ZN1S9f_inline2Ev" %t &&
inline void f_inline2() { } inline void f_inline2() { }
// RUN: grep "define internal void @_ZN1S1gEv" %t // RUN: grep "define linkonce_odr void @_ZN1S1gEv" %t &&
static void g() { } static void g() { }
static void f();
}; };
// RUN: grep "define void @_ZN1S1fEv" %t
void S::f() {
}
void test2() { void test2() {
S s; S s;