1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc namespace N { 4*f4a2713aSLionel Sambuc namespace M { 5*f4a2713aSLionel Sambuc template<typename T> struct Promote; 6*f4a2713aSLionel Sambuc 7*f4a2713aSLionel Sambuc template<> struct Promote<short> { 8*f4a2713aSLionel Sambuc typedef int type; 9*f4a2713aSLionel Sambuc }; 10*f4a2713aSLionel Sambuc 11*f4a2713aSLionel Sambuc template<> struct Promote<int> { 12*f4a2713aSLionel Sambuc typedef int type; 13*f4a2713aSLionel Sambuc }; 14*f4a2713aSLionel Sambuc 15*f4a2713aSLionel Sambuc template<> struct Promote<float> { 16*f4a2713aSLionel Sambuc typedef double type; 17*f4a2713aSLionel Sambuc }; 18*f4a2713aSLionel Sambuc ret_intptr(int * ip)19*f4a2713aSLionel Sambuc Promote<short>::type *ret_intptr(int* ip) { return ip; } ret_intptr2(int * ip)20*f4a2713aSLionel Sambuc Promote<int>::type *ret_intptr2(int* ip) { return ip; } 21*f4a2713aSLionel Sambuc } 22*f4a2713aSLionel Sambuc ret_intptr3(int * ip)23*f4a2713aSLionel Sambuc M::Promote<int>::type *ret_intptr3(int* ip) { return ip; } ret_intptr4(int * ip)24*f4a2713aSLionel Sambuc M::template Promote<int>::type *ret_intptr4(int* ip) { return ip; } // expected-warning{{'template' keyword outside of a template}} 25*f4a2713aSLionel Sambuc M::template Promote<int> pi; // expected-warning{{'template' keyword outside of a template}} 26*f4a2713aSLionel Sambuc } 27*f4a2713aSLionel Sambuc ret_intptr5(int * ip)28*f4a2713aSLionel SambucN::M::Promote<int>::type *ret_intptr5(int* ip) { return ip; } ret_intptr6(int * ip)29*f4a2713aSLionel Sambuc::N::M::Promote<int>::type *ret_intptr6(int* ip) { return ip; } 30*f4a2713aSLionel Sambuc 31*f4a2713aSLionel Sambuc 32*f4a2713aSLionel Sambuc N::M::template; // expected-error{{expected unqualified-id}} 33*f4a2713aSLionel Sambuc N::M::template Promote; // expected-error{{expected unqualified-id}} 34*f4a2713aSLionel Sambuc 35*f4a2713aSLionel Sambuc namespace N { 36*f4a2713aSLionel Sambuc template<typename T> struct A; 37*f4a2713aSLionel Sambuc 38*f4a2713aSLionel Sambuc template<> 39*f4a2713aSLionel Sambuc struct A<int> { 40*f4a2713aSLionel Sambuc struct X; 41*f4a2713aSLionel Sambuc }; 42*f4a2713aSLionel Sambuc 43*f4a2713aSLionel Sambuc struct B; 44*f4a2713aSLionel Sambuc } 45*f4a2713aSLionel Sambuc 46*f4a2713aSLionel Sambuc struct ::N::A<int>::X { 47*f4a2713aSLionel Sambuc int foo; 48*f4a2713aSLionel Sambuc }; 49*f4a2713aSLionel Sambuc 50*f4a2713aSLionel Sambuc template<typename T> 51*f4a2713aSLionel Sambuc struct TestA { 52*f4a2713aSLionel Sambuc typedef typename N::template B<T>::type type; // expected-error{{'B' following the 'template' keyword does not refer to a template}} \ 53*f4a2713aSLionel Sambuc // expected-error{{expected member name}} 54*f4a2713aSLionel Sambuc }; 55*f4a2713aSLionel Sambuc 56*f4a2713aSLionel Sambuc // Reduced from a Boost failure. 57*f4a2713aSLionel Sambuc namespace test1 { 58*f4a2713aSLionel Sambuc template <class T> struct pair { 59*f4a2713aSLionel Sambuc T x; 60*f4a2713aSLionel Sambuc T y; 61*f4a2713aSLionel Sambuc 62*f4a2713aSLionel Sambuc static T pair<T>::* const mem_array[2]; 63*f4a2713aSLionel Sambuc }; 64*f4a2713aSLionel Sambuc 65*f4a2713aSLionel Sambuc template <class T> 66*f4a2713aSLionel Sambuc T pair<T>::* const pair<T>::mem_array[2] = { &pair<T>::x, &pair<T>::y }; 67*f4a2713aSLionel Sambuc } 68*f4a2713aSLionel Sambuc 69*f4a2713aSLionel Sambuc typedef int T; 70*f4a2713aSLionel Sambuc namespace N1 { 71*f4a2713aSLionel Sambuc template<typename T> T f0(); 72*f4a2713aSLionel Sambuc } 73*f4a2713aSLionel Sambuc f0()74*f4a2713aSLionel Sambuctemplate<typename T> T N1::f0() { } 75*f4a2713aSLionel Sambuc 76*f4a2713aSLionel Sambuc namespace PR7385 { 77*f4a2713aSLionel Sambuc template< typename > struct has_xxx0 78*f4a2713aSLionel Sambuc { 79*f4a2713aSLionel Sambuc template< typename > struct has_xxx0_introspect 80*f4a2713aSLionel Sambuc { 81*f4a2713aSLionel Sambuc template< typename > struct has_xxx0_substitute ; 82*f4a2713aSLionel Sambuc template< typename V > 83*f4a2713aSLionel Sambuc int int00( has_xxx0_substitute < typename V::template xxx< > > = 0 ); 84*f4a2713aSLionel Sambuc }; 85*f4a2713aSLionel Sambuc static const int value = has_xxx0_introspect<int>::value; // expected-error{{no member named 'value'}} 86*f4a2713aSLionel Sambuc typedef int type; 87*f4a2713aSLionel Sambuc }; 88*f4a2713aSLionel Sambuc 89*f4a2713aSLionel Sambuc has_xxx0<int>::type t; // expected-note{{instantiation of}} 90*f4a2713aSLionel Sambuc } 91*f4a2713aSLionel Sambuc 92*f4a2713aSLionel Sambuc namespace PR7725 { 93*f4a2713aSLionel Sambuc template<class ignored> struct TypedefProvider; 94*f4a2713aSLionel Sambuc template<typename T> 95*f4a2713aSLionel Sambuc struct TemplateClass : public TypedefProvider<T> 96*f4a2713aSLionel Sambuc { PrintSelfPR7725::TemplateClass97*f4a2713aSLionel Sambuc void PrintSelf() { 98*f4a2713aSLionel Sambuc TemplateClass::Test::PrintSelf(); 99*f4a2713aSLionel Sambuc } 100*f4a2713aSLionel Sambuc }; 101*f4a2713aSLionel Sambuc } 102*f4a2713aSLionel Sambuc 103*f4a2713aSLionel Sambuc namespace PR9226 { 104*f4a2713aSLionel Sambuc template<typename a> nt()105*f4a2713aSLionel Sambuc void nt() // expected-note{{function template 'nt' declared here}} 106*f4a2713aSLionel Sambuc { nt<>:: } // expected-error{{qualified name refers into a specialization of function template 'nt'}} \ 107*f4a2713aSLionel Sambuc // expected-error{{expected unqualified-id}} 108*f4a2713aSLionel Sambuc 109*f4a2713aSLionel Sambuc template<typename T> 110*f4a2713aSLionel Sambuc void f(T*); // expected-note{{function template 'f' declared here}} 111*f4a2713aSLionel Sambuc 112*f4a2713aSLionel Sambuc template<typename T> 113*f4a2713aSLionel Sambuc void f(T*, T*); // expected-note{{function template 'f' declared here}} 114*f4a2713aSLionel Sambuc g()115*f4a2713aSLionel Sambuc void g() { 116*f4a2713aSLionel Sambuc f<int>:: // expected-error{{qualified name refers into a specialization of function template 'f'}} 117*f4a2713aSLionel Sambuc } // expected-error{{expected unqualified-id}} 118*f4a2713aSLionel Sambuc 119*f4a2713aSLionel Sambuc struct X { 120*f4a2713aSLionel Sambuc template<typename T> void f(); // expected-note{{function template 'f' declared here}} 121*f4a2713aSLionel Sambuc }; 122*f4a2713aSLionel Sambuc 123*f4a2713aSLionel Sambuc template<typename T, typename U> 124*f4a2713aSLionel Sambuc struct Y { 125*f4a2713aSLionel Sambuc typedef typename T::template f<U> type; // expected-error{{template name refers to non-type template 'X::f'}} 126*f4a2713aSLionel Sambuc }; 127*f4a2713aSLionel Sambuc 128*f4a2713aSLionel Sambuc Y<X, int> yxi; // expected-note{{in instantiation of template class 'PR9226::Y<PR9226::X, int>' requested here}} 129*f4a2713aSLionel Sambuc } 130*f4a2713aSLionel Sambuc 131*f4a2713aSLionel Sambuc namespace PR9449 { 132*f4a2713aSLionel Sambuc template <typename T> 133*f4a2713aSLionel Sambuc struct s; // expected-note{{template is declared here}} 134*f4a2713aSLionel Sambuc 135*f4a2713aSLionel Sambuc template <typename T> f()136*f4a2713aSLionel Sambuc void f() { 137*f4a2713aSLionel Sambuc int s<T>::template n<T>::* f; // expected-error{{implicit instantiation of undefined template 'PR9449::s<int>'}} \ 138*f4a2713aSLionel Sambuc // expected-error{{following the 'template' keyword}} 139*f4a2713aSLionel Sambuc } 140*f4a2713aSLionel Sambuc 141*f4a2713aSLionel Sambuc template void f<int>(); // expected-note{{in instantiation of}} 142*f4a2713aSLionel Sambuc } 143