From: Nico Weber Date: Tue, 20 Dec 2011 20:32:49 +0000 (+0000) Subject: Fix a crash on invalid, http://llvm.org/pr11599 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c7feca0392f7a55e1efa56fd1579881cd59d03d3;p=clang Fix a crash on invalid, http://llvm.org/pr11599 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146988 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index e86912a521..7c3165206c 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -1709,6 +1709,13 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation, << Context.getTypeDeclType(Instantiation); Diag(Pattern->getLocation(), diag::note_template_decl_here); } + + // In general, Instantiation isn't marked invalid to get more than one + // error for multiple undefined instantiations. But the code that does + // explicit declaration -> explicit definition conversion can't handle + // invalid declarations, so mark as invalid in that case. + if (TSK == TSK_ExplicitInstantiationDeclaration) + Instantiation->setInvalidDecl(); return true; } Pattern = PatternDef; @@ -1719,7 +1726,7 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation, MSInfo->setTemplateSpecializationKind(TSK); MSInfo->setPointOfInstantiation(PointOfInstantiation); } else if (ClassTemplateSpecializationDecl *Spec - = dyn_cast(Instantiation)) { + = dyn_cast(Instantiation)) { Spec->setTemplateSpecializationKind(TSK); Spec->setPointOfInstantiation(PointOfInstantiation); } @@ -1888,7 +1895,8 @@ Sema::InstantiateClassTemplateSpecialization( // If this is an explicit instantiation definition, mark the // vtable as used. - if (TSK == TSK_ExplicitInstantiationDefinition) + if (TSK == TSK_ExplicitInstantiationDefinition && + !ClassTemplateSpec->isInvalidDecl()) MarkVTableUsed(PointOfInstantiation, ClassTemplateSpec, true); return false; diff --git a/test/CXX/temp/temp.spec/temp.explicit/p3.cpp b/test/CXX/temp/temp.spec/temp.explicit/p3.cpp index ff1438285e..38ae7688a0 100644 --- a/test/CXX/temp/temp.spec/temp.explicit/p3.cpp +++ b/test/CXX/temp/temp.spec/temp.explicit/p3.cpp @@ -72,3 +72,10 @@ namespace PR7979 { template int S::i; template void S::S2::h() {} } + +namespace PR11599 { + template class BasicStringPiece; // expected-note {{template is declared here}} + + extern template class BasicStringPiece; // expected-error{{explicit instantiation of undefined template 'PR11599::BasicStringPiece}} + template class BasicStringPiece; +}