Fix crash-on-invalid bug in template instantiation.

Get rid of code-path that (according to Richard Smith) is not needed but
leads to a crasher bug when assuming a template has been fully
instantiated and thus has a definition.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240752 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Manuel Klimek 2015-06-26 02:15:04 +00:00
parent ac7732b727
commit b839522da5
2 changed files with 9 additions and 27 deletions

View File

@ -2269,33 +2269,6 @@ bool Sema::InstantiateClassTemplateSpecialization(
// Perform the actual instantiation on the canonical declaration.
ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>(
ClassTemplateSpec->getCanonicalDecl());
// Check whether we have already instantiated or specialized this class
// template specialization.
if (ClassTemplateSpec->getSpecializationKind() != TSK_Undeclared) {
if (ClassTemplateSpec->getSpecializationKind() ==
TSK_ExplicitInstantiationDeclaration &&
TSK == TSK_ExplicitInstantiationDefinition) {
// An explicit instantiation definition follows an explicit instantiation
// declaration (C++0x [temp.explicit]p10); go ahead and perform the
// explicit instantiation.
ClassTemplateSpec->setSpecializationKind(TSK);
// If this is an explicit instantiation definition, mark the
// vtable as used.
if (TSK == TSK_ExplicitInstantiationDefinition &&
!ClassTemplateSpec->isInvalidDecl())
MarkVTableUsed(PointOfInstantiation, ClassTemplateSpec, true);
return false;
}
// We can only instantiate something that hasn't already been
// instantiated or specialized. Fail without any diagnostics: our
// caller will provide an error message.
return true;
}
if (ClassTemplateSpec->isInvalidDecl())
return true;

View File

@ -0,0 +1,9 @@
// RUN: not %clang_cc1 -fsyntax-only -std=c++11 -ferror-limit 1 %s 2>&1 | FileCheck %s
unknown_type foo(unknown_type);
// CHECK: fatal error: too many errors emitted, stopping now
template <typename>
class Bar {};
extern template class Bar<int>;
template class Bar<int>;