r185038 - Handle all TemplateArguments in trivial TypeLocs.

Eli Friedman eli.friedman at gmail.com
Wed Jun 26 16:30:51 PDT 2013


Author: efriedma
Date: Wed Jun 26 18:30:50 2013
New Revision: 185038

URL: http://llvm.org/viewvc/llvm-project?rev=185038&view=rev
Log:
Handle all TemplateArguments in trivial TypeLocs.

Armed with a much better understanding of what
TemplateSpecializationTypeLoc::initializeArgLocs actually does, I now
understand that it's fine to just use an empty TemplateArgumentLocInfo
for Integral, Declaration, and NullPtr TemplateArguments.

Fixes PR14281. (The testcases are actually derived from libcxx_test in
deduction-crash.cpp because the original testcase was impossible to reduce.)

Modified:
    cfe/trunk/lib/AST/TypeLoc.cpp
    cfe/trunk/test/SemaTemplate/deduction-crash.cpp

Modified: cfe/trunk/lib/AST/TypeLoc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypeLoc.cpp?rev=185038&r1=185037&r2=185038&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TypeLoc.cpp (original)
+++ cfe/trunk/lib/AST/TypeLoc.cpp Wed Jun 26 18:30:50 2013
@@ -357,10 +357,13 @@ void TemplateSpecializationTypeLoc::init
   for (unsigned i = 0, e = NumArgs; i != e; ++i) {
     switch (Args[i].getKind()) {
     case TemplateArgument::Null: 
-    case TemplateArgument::Declaration:
+      llvm_unreachable("Impossible TemplateArgument");
+
     case TemplateArgument::Integral:
+    case TemplateArgument::Declaration:
     case TemplateArgument::NullPtr:
-      llvm_unreachable("Impossible TemplateArgument");
+      ArgInfos[i] = TemplateArgumentLocInfo();
+      break;
 
     case TemplateArgument::Expression:
       ArgInfos[i] = TemplateArgumentLocInfo(Args[i].getAsExpr());

Modified: cfe/trunk/test/SemaTemplate/deduction-crash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/deduction-crash.cpp?rev=185038&r1=185037&r2=185038&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/deduction-crash.cpp (original)
+++ cfe/trunk/test/SemaTemplate/deduction-crash.cpp Wed Jun 26 18:30:50 2013
@@ -1,8 +1,8 @@
-// RUN: %clang_cc1 -fsyntax-only %s 2>&1| FileCheck %s
+// RUN: %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: 15 errors
+// CHECK: 16 errors
 
 // PR7511
 template<a>
@@ -110,3 +110,35 @@ namespace libcxx_test {
   template <class T> struct B {};
   __pointer_traits_element_type<B<int>, true>::type x;
 }
+
+namespace PR14281_part1 {
+  template <class P, int> struct A;
+  template <class P> struct A<P, 1>;
+  template <template <class, int> class S, class T> struct A<S<T, 1>, 1> {
+    typedef char type;
+  };
+  template <class T, int i> struct B {};
+  A<B<int, 1>, 1>::type x;
+}
+
+namespace PR14281_part2 {
+  typedef decltype(nullptr) nullptr_t;
+  template <class P, nullptr_t> struct A;
+  template <class P> struct A<P, nullptr>;
+  template <template <class, nullptr_t> class S, class T> struct A<S<T, nullptr>, nullptr> {
+    typedef char type;
+  };
+  template <class T, nullptr_t i> struct B {};
+  A<B<int, nullptr>, nullptr>::type x;
+}
+
+namespace PR14281_part3 {
+  extern int some_decl;
+  template <class P, int*> struct A;
+  template <class P> struct A<P, &some_decl>;
+  template <template <class, int*> class S, class T> struct A<S<T, &some_decl>, &some_decl> {
+    typedef char type;
+  };
+  template <class T, int* i> struct B {};
+  A<B<int, &some_decl>, &some_decl>::type x;
+}





More information about the cfe-commits mailing list