diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2010-03-22 23:12:48 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2010-03-22 23:12:48 +0000 |
commit | b0f65ca9853d1148211a38736141c8ccf2aa4a1d (patch) | |
tree | 1592d98092d8b8b59d79c3dd1b5b7e9bf93c8c5d | |
parent | 0647a7b9ad844565b8a4b5e1a5de882dd64efabf (diff) |
A fixed version of r99174 which also includes a test that we emit vtables when
we see an specialization definition ever if we then see a extern template declaration.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99226 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 2 | ||||
-rw-r--r-- | lib/Sema/SemaTemplate.cpp | 11 | ||||
-rw-r--r-- | test/CodeGenCXX/PR6677.cpp | 33 |
3 files changed, 44 insertions, 2 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 13a7ead76b..1522d6399a 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -5889,7 +5889,7 @@ static bool needsVtable(CXXMethodDecl *MD, ASTContext &Context) { break; case TSK_ExplicitInstantiationDeclaration: - return true; //FIXME: This looks wrong. + return false; case TSK_ExplicitInstantiationDefinition: // This is method of a explicit instantiation; mark all of the virtual diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 434d5563e1..abe9363352 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -4388,8 +4388,17 @@ Sema::ActOnExplicitInstantiation(Scope *S, // Instantiate the members of this class template specialization. Def = cast_or_null<ClassTemplateSpecializationDecl>( Specialization->getDefinition()); - if (Def) + if (Def) { + TemplateSpecializationKind Old_TSK = Def->getTemplateSpecializationKind(); + + // Fix a TSK_ExplicitInstantiationDeclaration followed by a + // TSK_ExplicitInstantiationDefinition + if (Old_TSK == TSK_ExplicitInstantiationDeclaration && + TSK == TSK_ExplicitInstantiationDefinition) + Def->setTemplateSpecializationKind(TSK); + InstantiateClassTemplateSpecializationMembers(TemplateNameLoc, Def, TSK); + } return DeclPtrTy::make(Specialization); } diff --git a/test/CodeGenCXX/PR6677.cpp b/test/CodeGenCXX/PR6677.cpp new file mode 100644 index 0000000000..8d168f1106 --- /dev/null +++ b/test/CodeGenCXX/PR6677.cpp @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s + +// CHECK-NOT: @_ZTVN5test118stdio_sync_filebufIwEE = constant +// CHECK: @_ZTVN5test018stdio_sync_filebufIwEE = constant + +namespace test0 { + struct basic_streambuf { + virtual ~basic_streambuf(); + }; + template<typename _CharT > + struct stdio_sync_filebuf : public basic_streambuf { + virtual void xsgetn(); + }; + + // This specialization should cause the vtable to be emitted, even with + // the following extern template declaration. + template<> void stdio_sync_filebuf<wchar_t>::xsgetn() { + } + extern template class stdio_sync_filebuf<wchar_t>; +} + +namespace test1 { + struct basic_streambuf { + virtual ~basic_streambuf(); + }; + template<typename _CharT > + struct stdio_sync_filebuf : public basic_streambuf { + virtual void xsgetn(); + }; + + // Just a declaration should not force the vtable to be emitted. + template<> void stdio_sync_filebuf<wchar_t>::xsgetn(); +} |