[cfe-commits] r84189 - in /cfe/trunk: lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/CXX/temp/temp.spec/p5.cpp
Douglas Gregor
dgregor at apple.com
Thu Oct 15 11:07:02 PDT 2009
Author: dgregor
Date: Thu Oct 15 13:07:02 2009
New Revision: 84189
URL: http://llvm.org/viewvc/llvm-project?rev=84189&view=rev
Log:
Make sure that we're diagnosing duplicate explicit instantiation definitions.
Added:
cfe/trunk/test/CXX/temp/temp.spec/p5.cpp
Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=84189&r1=84188&r2=84189&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu Oct 15 13:07:02 2009
@@ -3818,8 +3818,11 @@
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 @@
}
FunctionDecl *PrevDecl = Specialization->getPreviousDeclaration();
+ if (!PrevDecl && Specialization->isThisDeclarationADefinition())
+ PrevDecl = Specialization;
+
if (PrevDecl) {
bool SuppressNew = false;
if (CheckSpecializationInstantiationRedecl(*this, D.getIdentifierLoc(), TSK,
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=84189&r1=84188&r2=84189&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Thu Oct 15 13:07:02 2009
@@ -1258,7 +1258,10 @@
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);
}
Added: cfe/trunk/test/CXX/temp/temp.spec/p5.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.spec/p5.cpp?rev=84189&view=auto
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.spec/p5.cpp (added)
+++ cfe/trunk/test/CXX/temp/temp.spec/p5.cpp Thu Oct 15 13:07:02 2009
@@ -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}}
More information about the cfe-commits
mailing list