[PATCH] D49766: Fix a crash when an error occurs in Template and the initializer is a nullptr for C++17

Balaji Iyer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 27 11:24:43 PDT 2018


bviyer updated this revision to Diff 157721.
bviyer added a comment.

I have fixed all the changes requested by Erik along with shortening the test case.


Repository:
  rC Clang

https://reviews.llvm.org/D49766

Files:
  include/clang/AST/TemplateBase.h
  test/SemaObjCXX/class-templ-error-null-init.mm


Index: test/SemaObjCXX/class-templ-error-null-init.mm
===================================================================
--- /dev/null
+++ test/SemaObjCXX/class-templ-error-null-init.mm
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17  -verify %s
+// expected-no-diagnostics
+template <typename a, int* = nullptr>
+struct e {
+    e(a) {}
+};
+e c(0);
Index: include/clang/AST/TemplateBase.h
===================================================================
--- include/clang/AST/TemplateBase.h
+++ include/clang/AST/TemplateBase.h
@@ -465,7 +465,12 @@
 
   TemplateArgumentLoc(const TemplateArgument &Argument, Expr *E)
       : Argument(Argument), LocInfo(E) {
-    assert(Argument.getKind() == TemplateArgument::Expression);
+
+    // Allow more additional argument kinds for the constructor.
+    assert(Argument.getKind() == TemplateArgument::NullPtr ||
+           Argument.getKind() == TemplateArgument::Integral ||
+           Argument.getKind() == TemplateArgument::Declaration ||
+           Argument.getKind() == TemplateArgument::Expression);
   }
 
   TemplateArgumentLoc(const TemplateArgument &Argument, 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49766.157721.patch
Type: text/x-patch
Size: 1135 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180727/0169b646/attachment.bin>


More information about the cfe-commits mailing list