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