From: Manuel Klimek Date: Fri, 26 Jun 2015 02:15:04 +0000 (+0000) Subject: Fix crash-on-invalid bug in template instantiation. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b839522da5dbe5253c9258c49ece2024960a1358;p=clang 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 --- diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 82ff7c0ca4..178a14e9ec 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -2269,33 +2269,6 @@ bool Sema::InstantiateClassTemplateSpecialization( // Perform the actual instantiation on the canonical declaration. ClassTemplateSpec = cast( 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; diff --git a/test/SemaTemplate/instantiate-explicitly-after-fatal.cpp b/test/SemaTemplate/instantiate-explicitly-after-fatal.cpp new file mode 100644 index 0000000000..9693d2fc6c --- /dev/null +++ b/test/SemaTemplate/instantiate-explicitly-after-fatal.cpp @@ -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 +class Bar {}; + +extern template class Bar; +template class Bar;