r304604 - Fix assertion failure if we can't deduce a template argument for a variable

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 2 15:53:07 PDT 2017


Author: rsmith
Date: Fri Jun  2 17:53:06 2017
New Revision: 304604

URL: http://llvm.org/viewvc/llvm-project?rev=304604&view=rev
Log:
Fix assertion failure if we can't deduce a template argument for a variable
template partial specialization.

In passing, fix the deduction-crash.cpp test to actually run all the tests. Due
to a typo, the last third of the file was being skipped by the parser and some
of the tests were not actually testing anything as a result. Switch from
FileCheck to -verify to make the problem more obvious and prevent this
happening again.

Modified:
    cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
    cfe/trunk/test/SemaTemplate/deduction-crash.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=304604&r1=304603&r2=304604&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Fri Jun  2 17:53:06 2017
@@ -2383,7 +2383,8 @@ static Sema::TemplateDeductionResult Con
     bool HasDefaultArg = false;
     TemplateDecl *TD = dyn_cast<TemplateDecl>(Template);
     if (!TD) {
-      assert(isa<ClassTemplatePartialSpecializationDecl>(Template));
+      assert(isa<ClassTemplatePartialSpecializationDecl>(Template) ||
+             isa<VarTemplatePartialSpecializationDecl>(Template));
       return Sema::TDK_Incomplete;
     }
 

Modified: cfe/trunk/test/SemaTemplate/deduction-crash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/deduction-crash.cpp?rev=304604&r1=304603&r2=304604&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/deduction-crash.cpp (original)
+++ cfe/trunk/test/SemaTemplate/deduction-crash.cpp Fri Jun  2 17:53:06 2017
@@ -1,14 +1,10 @@
-// RUN: not %clang_cc1 -fsyntax-only %s -std=c++11 2>&1| FileCheck %s
-
-// Note that the error count below doesn't matter. We just want to
-// make sure that the parser doesn't crash.
-// CHECK: 17 errors
+// RUN: %clang_cc1 -fsyntax-only %s -std=c++1z -verify
 
 // PR7511
-template<a>
+template<a> // expected-error +{{}}
 struct int_;
 
-template<a>
+template<a> // expected-error +{{}}
 template<int,typename T1,typename>
 struct ac
 {
@@ -17,7 +13,7 @@ struct ac
 
 template<class>struct aaa
 {
-  typedef ac<1,int,int>::ae ae
+  typedef ac<1,int,int>::ae ae // expected-error +{{}}
 };
 
 template<class>
@@ -36,19 +32,19 @@ struct state_machine
     struct In;
     
     template<int my>
-    struct In<a::int_<aaa::a>,my>;
+    struct In<a::int_<aaa::a>,my>; // expected-error +{{}}
         
     template<class Event>
     int process(Event)
     {
-      In<a::int_<0> > a;
+      In<a::int_<0> > a; // expected-error +{{}}
     }
-  }
+  } // expected-error +{{}}
   template<class Event>
   int ant(Event)
   {
     region_processing_helper<int>* helper;
-    helper->process(0)
+    helper->process(0) // expected-error +{{}}
   }
 };
 
@@ -81,21 +77,21 @@ void endl( ) ;
 
 extern basic_ostream<char> cout;
 
-int operator<<( basic_ostream<char> , pair ) ;
+int operator<<( basic_ostream<char> , pair ) ; // expected-note +{{}}
 
 void register_object_imp ( )
 {
-cout << endl<1>;
+cout << endl<1>; // expected-error +{{}}
 }
 
 // PR12933
-namespacae PR12933 {
-  template<typename S>
+namespace PR12933 {
+  template<typename S> // expected-error +{{}}
     template<typename T>
     void function(S a, T b) {}
 
   int main() {
-    function(0, 1);
+    function(0, 1); // expected-error +{{}}
     return 0;
   }
 }
@@ -142,3 +138,9 @@ namespace PR14281_part3 {
   template <class T, int* i> struct B {};
   A<B<int, &some_decl>, &some_decl>::type x;
 }
+
+namespace var_template_partial_spec_incomplete {
+  template<typename T> int n;
+  template<typename T, typename U = void> int n<T *>; // expected-error +{{}} expected-note {{}}
+  int k = n<void *>;
+}




More information about the cfe-commits mailing list