From: Eli Friedman Date: Wed, 26 Jun 2013 23:30:50 +0000 (+0000) Subject: Handle all TemplateArguments in trivial TypeLocs. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=33b90b34990a7738adebae30ef7ebf9d578ce9ae;p=clang 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.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185038 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/TypeLoc.cpp b/lib/AST/TypeLoc.cpp index c47bde8dde..080316dc3e 100644 --- a/lib/AST/TypeLoc.cpp +++ b/lib/AST/TypeLoc.cpp @@ -357,10 +357,13 @@ void TemplateSpecializationTypeLoc::initializeArgLocs(ASTContext &Context, 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()); diff --git a/test/SemaTemplate/deduction-crash.cpp b/test/SemaTemplate/deduction-crash.cpp index 0714c5e516..3b07cc2ed5 100644 --- a/test/SemaTemplate/deduction-crash.cpp +++ b/test/SemaTemplate/deduction-crash.cpp @@ -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 @@ -110,3 +110,35 @@ namespace libcxx_test { template struct B {}; __pointer_traits_element_type, true>::type x; } + +namespace PR14281_part1 { + template struct A; + template struct A; + template