[PATCH] Fix crash-on-invalid bug in template instantiation.
Manuel Klimek
klimek at google.com
Mon Jun 22 17:17:23 PDT 2015
Hi rsmith,
When a template is instantiated after a fatal error has occurred,
template instantiation is aborted. In that case, we need to mark the
instantiated decl as invalid, otherwise we try to access it later.
http://reviews.llvm.org/D10622
Files:
lib/Sema/SemaTemplateInstantiate.cpp
test/SemaTemplate/instantiate-explicitly-after-fatal.cpp
Index: lib/Sema/SemaTemplateInstantiate.cpp
===================================================================
--- lib/Sema/SemaTemplateInstantiate.cpp
+++ lib/Sema/SemaTemplateInstantiate.cpp
@@ -1939,8 +1939,10 @@
}
InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation);
- if (Inst.isInvalid())
+ if (Inst.isInvalid()) {
+ Instantiation->setInvalidDecl(true);
return true;
+ }
// Enter the scope of this instantiation. We don't use
// PushDeclContext because we don't have a scope.
Index: test/SemaTemplate/instantiate-explicitly-after-fatal.cpp
===================================================================
--- /dev/null
+++ 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 <typename>
+class Bar {};
+
+extern template class Bar<int>;
+template class Bar<int>;
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10622.28179.patch
Type: text/x-patch
Size: 1034 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150623/c7db845d/attachment.bin>
More information about the cfe-commits
mailing list