r240752 - Fix crash-on-invalid bug in template instantiation.
Manuel Klimek
klimek at google.com
Thu Jun 25 19:15:04 PDT 2015
Author: klimek
Date: Thu Jun 25 21:15:04 2015
New Revision: 240752
URL: http://llvm.org/viewvc/llvm-project?rev=240752&view=rev
Log:
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.
Added:
cfe/trunk/test/SemaTemplate/instantiate-explicitly-after-fatal.cpp
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=240752&r1=240751&r2=240752&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Thu Jun 25 21:15:04 2015
@@ -2269,33 +2269,6 @@ bool Sema::InstantiateClassTemplateSpeci
// 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;
Added: cfe/trunk/test/SemaTemplate/instantiate-explicitly-after-fatal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-explicitly-after-fatal.cpp?rev=240752&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-explicitly-after-fatal.cpp (added)
+++ cfe/trunk/test/SemaTemplate/instantiate-explicitly-after-fatal.cpp Thu Jun 25 21:15:04 2015
@@ -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>;
More information about the cfe-commits
mailing list