bviyer created this revision.
bviyer added reviewers: arphaman, erik.pilkington, dexonsmith.
Herald added a subscriber: cfe-commits.

When the error has occurred for one of the variables inside a template, the Loc 
function will try to find the end-location of the final item. If this variable 
is default initialized to nullptr, then the templateArgumentLoc function is 
invoked. It has an assert to see if the Argument's kind is Expression. If the 
default initializer is a nullptr, then the argument's kind will be NullPtr, not 
Expression. This will cause a compiler crash. This patch will allow NullPtr as 
a possibility for expression's kind.


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,8 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17  -verify %s
+
+template <typename a, typename b, d * = nullptr> // expected-error {{unknown 
type name 'd'}}
+class e {
+  public:
+    e(a,b) {}
+};
+      e c([]{} ,[]{} );
Index: include/clang/AST/TemplateBase.h
===================================================================
--- include/clang/AST/TemplateBase.h
+++ include/clang/AST/TemplateBase.h
@@ -465,7 +465,14 @@
 
   TemplateArgumentLoc(const TemplateArgument &Argument, Expr *E)
       : Argument(Argument), LocInfo(E) {
-    assert(Argument.getKind() == TemplateArgument::Expression);
+
+    /* When an error occurs in a template value that is defaulted to
+       nullptr then the nullptr is left as-is and this function will
+       take in an argument that is of type NullPtr when compiled using
+       C++17 standard.  This is to make sure the compiler does not crash
+       and proceeds through.  */
+    assert(Argument.getKind() == TemplateArgument::NullPtr ||
+           Argument.getKind() == TemplateArgument::Expression);
   }
 
   TemplateArgumentLoc(const TemplateArgument &Argument, 


Index: test/SemaObjCXX/class-templ-error-null-init.mm
===================================================================
--- /dev/null
+++ test/SemaObjCXX/class-templ-error-null-init.mm
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17  -verify %s
+
+template <typename a, typename b, d * = nullptr> // expected-error {{unknown type name 'd'}}
+class e {
+  public:
+    e(a,b) {}
+};
+      e c([]{} ,[]{} );
Index: include/clang/AST/TemplateBase.h
===================================================================
--- include/clang/AST/TemplateBase.h
+++ include/clang/AST/TemplateBase.h
@@ -465,7 +465,14 @@
 
   TemplateArgumentLoc(const TemplateArgument &Argument, Expr *E)
       : Argument(Argument), LocInfo(E) {
-    assert(Argument.getKind() == TemplateArgument::Expression);
+
+    /* When an error occurs in a template value that is defaulted to
+       nullptr then the nullptr is left as-is and this function will
+       take in an argument that is of type NullPtr when compiled using
+       C++17 standard.  This is to make sure the compiler does not crash
+       and proceeds through.  */
+    assert(Argument.getKind() == TemplateArgument::NullPtr ||
+           Argument.getKind() == TemplateArgument::Expression);
   }
 
   TemplateArgumentLoc(const TemplateArgument &Argument, 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to