blob: 635687d4f6b71b53813d0a8685e8bbbce03118d2 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregor39a8de12009-02-25 19:37:18 +00002
3namespace N {
4 namespace M {
Chris Lattnerf4382f52009-04-14 22:17:06 +00005 template<typename T> struct Promote;
Douglas Gregor39a8de12009-02-25 19:37:18 +00006
7 template<> struct Promote<short> {
8 typedef int type;
9 };
10
11 template<> struct Promote<int> {
12 typedef int type;
13 };
14
15 template<> struct Promote<float> {
16 typedef double type;
17 };
18
19 Promote<short>::type *ret_intptr(int* ip) { return ip; }
20 Promote<int>::type *ret_intptr2(int* ip) { return ip; }
21 }
22
23 M::Promote<int>::type *ret_intptr3(int* ip) { return ip; }
Douglas Gregor1a15dae2010-06-16 22:31:08 +000024 M::template Promote<int>::type *ret_intptr4(int* ip) { return ip; } // expected-warning{{'template' keyword outside of a template}}
Douglas Gregord6ab2322010-06-16 23:00:59 +000025 M::template Promote<int> pi; // expected-warning{{'template' keyword outside of a template}}
Douglas Gregor39a8de12009-02-25 19:37:18 +000026}
27
28N::M::Promote<int>::type *ret_intptr5(int* ip) { return ip; }
29::N::M::Promote<int>::type *ret_intptr6(int* ip) { return ip; }
30
31
Douglas Gregor7bb87fc2009-11-11 16:39:34 +000032N::M::template; // expected-error{{expected unqualified-id}}
33N::M::template Promote; // expected-error{{expected unqualified-id}}
Douglas Gregor39a8de12009-02-25 19:37:18 +000034
35namespace N {
36 template<typename T> struct A;
37
38 template<>
39 struct A<int> {
40 struct X;
41 };
Douglas Gregorc45c2322009-03-31 00:43:58 +000042
43 struct B;
Douglas Gregor39a8de12009-02-25 19:37:18 +000044}
45
46struct ::N::A<int>::X {
47 int foo;
48};
Douglas Gregorc45c2322009-03-31 00:43:58 +000049
Douglas Gregorc45c2322009-03-31 00:43:58 +000050template<typename T>
51struct TestA {
Douglas Gregor7bb87fc2009-11-11 16:39:34 +000052 typedef typename N::template B<T>::type type; // expected-error{{'B' following the 'template' keyword does not refer to a template}} \
Douglas Gregor7bb87fc2009-11-11 16:39:34 +000053 // expected-error{{expected member name}}
Douglas Gregorc45c2322009-03-31 00:43:58 +000054};
John McCall63b43852010-04-29 23:50:39 +000055
56// Reduced from a Boost failure.
57namespace test1 {
58 template <class T> struct pair {
59 T x;
60 T y;
61
62 static T pair<T>::* const mem_array[2];
63 };
64
65 template <class T>
66 T pair<T>::* const pair<T>::mem_array[2] = { &pair<T>::x, &pair<T>::y };
67}
Douglas Gregor00b4b032010-05-14 04:53:42 +000068
69typedef int T;
70namespace N1 {
71 template<typename T> T f0();
72}
73
74template<typename T> T N1::f0() { }
Douglas Gregore2872d02010-06-17 16:03:49 +000075
76namespace PR7385 {
77 template< typename > struct has_xxx0
78 {
79 template< typename > struct has_xxx0_introspect
80 {
81 template< typename > struct has_xxx0_substitute ;
82 template< typename V >
83 int int00( has_xxx0_substitute < typename V::template xxx< > > = 0 );
84 };
85 static const int value = has_xxx0_introspect<int>::value; // expected-error{{no member named 'value'}}
86 typedef int type;
87 };
88
89 has_xxx0<int>::type t; // expected-note{{instantiation of}}
90}
Douglas Gregorac7cbd82010-07-28 14:49:07 +000091
92namespace PR7725 {
93 template<class ignored> struct TypedefProvider;
94 template<typename T>
95 struct TemplateClass : public TypedefProvider<T>
96 {
97 void PrintSelf() {
98 TemplateClass::Test::PrintSelf();
99 }
100 };
101}
Douglas Gregor6cd9d4a2011-03-04 21:37:14 +0000102
103namespace PR9226 {
104 template<typename a>
105 void nt() // expected-note{{function template 'nt' declared here}}
106 { nt<>:: } // expected-error{{qualified name refers into a specialization of function template 'nt'}} \
107 // expected-error{{expected unqualified-id}}
108
109 template<typename T>
110 void f(T*); // expected-note{{function template 'f' declared here}}
111
112 template<typename T>
113 void f(T*, T*); // expected-note{{function template 'f' declared here}}
114
115 void g() {
116 f<int>:: // expected-error{{qualified name refers into a specialization of function template 'f'}}
117 } // expected-error{{expected unqualified-id}}
118
119 struct X {
120 template<typename T> void f(); // expected-note{{function template 'f' declared here}}
121 };
122
123 template<typename T, typename U>
124 struct Y {
125 typedef typename T::template f<U> type; // expected-error{{template name refers to non-type template 'X::f'}}
126 };
127
128 Y<X, int> yxi; // expected-note{{in instantiation of template class 'PR9226::Y<PR9226::X, int>' requested here}}
129}
Douglas Gregord078bd22011-03-11 23:27:41 +0000130
131namespace PR9449 {
132 template <typename T>
133 struct s; // expected-note{{template is declared here}}
134
135 template <typename T>
136 void f() {
137 int s<T>::template n<T>::* f; // expected-error{{implicit instantiation of undefined template 'PR9449::s<int>'}} \
138 // expected-error{{following the 'template' keyword}}
139 }
140
141 template void f<int>(); // expected-note{{in instantiation of}}
142}