Author: rsmith
Date: Tue Dec  3 18:56:29 2013
New Revision: 196337

URL: http://llvm.org/viewvc/llvm-project?rev=196337&view=rev
Log:
Fix crash if a dependent template-id was assumed to be a type but instantiates
to a variable template specialization.

Modified:
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=196337&r1=196336&r2=196337&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Tue Dec  3 18:56:29 2013
@@ -1959,7 +1959,8 @@ QualType Sema::CheckTemplateIdType(Templ
                                                           TemplateArgs);
 
   TemplateDecl *Template = Name.getAsTemplateDecl();
-  if (!Template || isa<FunctionTemplateDecl>(Template)) {
+  if (!Template || isa<FunctionTemplateDecl>(Template) ||
+      isa<VarTemplateDecl>(Template)) {
     // We might have a substituted template template parameter pack. If so,
     // build a template specialization type for it.
     if (Name.getAsSubstTemplateTemplateParmPack())

Modified: cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp?rev=196337&r1=196336&r2=196337&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp Tue Dec  3 
18:56:29 2013
@@ -291,6 +291,30 @@ namespace in_class_template {
     template<typename T> template<typename...U> T A<T>::y<tuple<U...> >[] = { 
U()... };
     static_assert(sizeof(A<int>::y<tuple<char, char, char> >) == 12, "");
   }
+
+  namespace bad_reference {
+    struct S {
+      template<typename T> static int A; // expected-note 4{{here}}
+    };
+
+    template<typename T> void f() {
+      typename T::template A<int> a; // expected-error {{template name refers 
to non-type template 'S::A'}}
+    }
+    template<typename T> void g() {
+      T::template A<int>::B = 0; // expected-error {{template name refers to 
non-type template 'S::A'}}
+    }
+    template<typename T> void h() {
+      class T::template A<int> c; // expected-error {{template name refers to 
non-type template 'S::A'}}
+    }
+
+    template<typename T>
+    struct X : T::template A<int> {}; // expected-error {{template name refers 
to non-type template 'S::A'}}
+
+    template void f<S>(); // expected-note {{in instantiation of}}
+    template void g<S>(); // expected-note {{in instantiation of}}
+    template void h<S>(); // expected-note {{in instantiation of}}
+    template struct X<S>; // expected-note {{in instantiation of}}
+  }
 }
 
 namespace in_nested_classes {


_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to