diff options
| author | Douglas Gregor <dgregor@apple.com> | 2009-10-15 18:07:02 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2009-10-15 18:07:02 +0000 |
| commit | 8f003d0fa361cf2236764c724a2009329737e5da (patch) | |
| tree | d761419830bf7fdced52a71b7a243f4ee8be6a26 /clang | |
| parent | 3d7e69f2c918b7128e4211f0b20ef7124bd46a5b (diff) | |
| download | bcm5719-llvm-8f003d0fa361cf2236764c724a2009329737e5da.tar.gz bcm5719-llvm-8f003d0fa361cf2236764c724a2009329737e5da.zip | |
Make sure that we're diagnosing duplicate explicit instantiation definitions.
llvm-svn: 84189
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Sema/SemaTemplate.cpp | 10 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 5 | ||||
| -rw-r--r-- | clang/test/CXX/temp/temp.spec/p5.cpp | 29 |
3 files changed, 41 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 8d7e199e7a8..730fea30b5a 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -3818,8 +3818,11 @@ Sema::ActOnExplicitInstantiation(Scope *S, CheckExplicitInstantiationScope(*this, Record, NameLoc, true); // Verify that it is okay to explicitly instantiate here. - if (CXXRecordDecl *PrevDecl - = cast_or_null<CXXRecordDecl>(Record->getPreviousDeclaration())) { + CXXRecordDecl *PrevDecl + = cast_or_null<CXXRecordDecl>(Record->getPreviousDeclaration()); + if (!PrevDecl && Record->getDefinition(Context)) + PrevDecl = Record; + if (PrevDecl) { MemberSpecializationInfo *MSInfo = PrevDecl->getMemberSpecializationInfo(); bool SuppressNew = false; assert(MSInfo && "No member specialization information?"); @@ -4065,6 +4068,9 @@ Sema::DeclResult Sema::ActOnExplicitInstantiation(Scope *S, } FunctionDecl *PrevDecl = Specialization->getPreviousDeclaration(); + if (!PrevDecl && Specialization->isThisDeclarationADefinition()) + PrevDecl = Specialization; + if (PrevDecl) { bool SuppressNew = false; if (CheckSpecializationInstantiationRedecl(*this, D.getIdentifierLoc(), TSK, diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index ca05d59abab..4bbef29de0b 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1258,7 +1258,10 @@ void Sema::InstantiateStaticDataMemberDefinition( if (Var) { Var->setPreviousDeclaration(OldVar); - Var->setTemplateSpecializationKind(OldVar->getTemplateSpecializationKind()); + MemberSpecializationInfo *MSInfo = OldVar->getMemberSpecializationInfo(); + assert(MSInfo && "Missing member specialization information?"); + Var->setTemplateSpecializationKind(MSInfo->getTemplateSpecializationKind(), + MSInfo->getPointOfInstantiation()); DeclGroupRef DG(Var); Consumer.HandleTopLevelDecl(DG); } diff --git a/clang/test/CXX/temp/temp.spec/p5.cpp b/clang/test/CXX/temp/temp.spec/p5.cpp new file mode 100644 index 00000000000..d5632e7f341 --- /dev/null +++ b/clang/test/CXX/temp/temp.spec/p5.cpp @@ -0,0 +1,29 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +template<typename T> inline void f(T) { } +template void f(int); // expected-note{{previous explicit instantiation}} +template void f(int); // expected-error{{duplicate explicit instantiation}} + +template<typename T> +struct X0 { + union Inner { }; + + void f(T) { } + + static T value; +}; + +template<typename T> +T X0<T>::value = 3.14; + +template struct X0<int>; // expected-note{{previous explicit instantiation}} +template struct X0<int>; // expected-error{{duplicate explicit instantiation}} + +template void X0<float>::f(float); // expected-note{{previous explicit instantiation}} +template void X0<float>::f(float); // expected-error{{duplicate explicit instantiation}} + +template union X0<float>::Inner; // expected-note{{previous explicit instantiation}} +template union X0<float>::Inner; // expected-error{{duplicate explicit instantiation}} + +template float X0<float>::value; // expected-note{{previous explicit instantiation}} +template float X0<float>::value; // expected-error{{duplicate explicit instantiation}} |

