r183325 - When the template specialization header is missing, set a valid source location for the template keyword when recovering.

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed Jun 5 10:52:25 PDT 2013


Author: akirtzidis
Date: Wed Jun  5 12:52:24 2013
New Revision: 183325

URL: http://llvm.org/viewvc/llvm-project?rev=183325&view=rev
Log:
When the template specialization header is missing, set a valid source location for the template keyword when recovering.

Otherwise ClassTemplateSpecializationDecl::getSourceRange() will mistakenly consider itself as an implicit partial specialization
and lead to a crash.

Fixes rdar://14063074

Modified:
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/test/Index/index-file.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=183325&r1=183324&r2=183325&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Jun  5 12:52:24 2013
@@ -5300,6 +5300,7 @@ Sema::ActOnClassTemplateSpecialization(S
   } else if (TUK != TUK_Friend) {
     Diag(KWLoc, diag::err_template_spec_needs_header)
       << FixItHint::CreateInsertion(KWLoc, "template<> ");
+    TemplateKWLoc = KWLoc;
     isExplicitSpecialization = true;
   }
 

Modified: cfe/trunk/test/Index/index-file.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-file.cpp?rev=183325&r1=183324&r2=183325&view=diff
==============================================================================
--- cfe/trunk/test/Index/index-file.cpp (original)
+++ cfe/trunk/test/Index/index-file.cpp Wed Jun  5 12:52:24 2013
@@ -4,7 +4,20 @@ extern "C" {
   template < typename T > *Allocate() { }
 }
 
+// rdar://14063074
+namespace rdar14063074 {
+template <typename T>
+struct TS {};
+struct TS<int> {};
+
+template <typename T>
+void tfoo() {}
+void tfoo<int>() {}
+}
+
 // RUN: c-index-test -index-file %s > %t
 // RUN: FileCheck %s -input-file=%t
 
 // CHECK: [indexDeclaration]: kind: type-alias | name: MyTypeAlias | {{.*}} | loc: 1:7
+// CHECK: [indexDeclaration]: kind: struct-template-spec | name: TS | {{.*}} | loc: 11:8
+// CHECK: [indexDeclaration]: kind: function-template-spec | name: tfoo | {{.*}} | loc: 15:6





More information about the cfe-commits mailing list