]> granicus.if.org Git - clang/commitdiff
Fix crash-on-invalid bug in template instantiation.
authorManuel Klimek <klimek@google.com>
Fri, 26 Jun 2015 02:15:04 +0000 (02:15 +0000)
committerManuel Klimek <klimek@google.com>
Fri, 26 Jun 2015 02:15:04 +0000 (02:15 +0000)
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

lib/Sema/SemaTemplateInstantiate.cpp
test/SemaTemplate/instantiate-explicitly-after-fatal.cpp [new file with mode: 0644]

index 82ff7c0ca4f50774e0151d3a71f8a19c2064eed4..178a14e9ecc00dc85554910482cbbefcf6888b7b 100644 (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;
   
diff --git a/test/SemaTemplate/instantiate-explicitly-after-fatal.cpp b/test/SemaTemplate/instantiate-explicitly-after-fatal.cpp
new file mode 100644 (file)
index 0000000..9693d2f
--- /dev/null
@@ -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>;