blob: bcd286ae044921ed083eb0a22002825986800158 [file] [log] [blame]
Douglas Gregor1edf5762012-06-28 21:43:01 +00001// RUN: %clang_cc1 -fms-extensions -fdelayed-template-parsing -fsyntax-only -verify -std=c++11 %s
Chandler Carruth03b77b32011-04-25 06:34:35 +00002
3template <class T>
4class A {
5 void foo() {
6 undeclared();
7 }
Francois Pichet81345182011-09-22 22:14:56 +00008 void foo2();
Chandler Carruth03b77b32011-04-25 06:34:35 +00009};
10
11template <class T>
12class B {
Nico Weber71e377d2015-01-17 02:33:17 +000013 void foo4() { } // expected-note {{previous definition is here}}
14 void foo4() { } // expected-error {{class member cannot be redeclared}}
David Majnemerea5092a2013-07-07 23:49:50 +000015 void foo5() { } // expected-note {{previous definition is here}}
Francois Pichet6dc4c162011-11-18 23:47:17 +000016
17 friend void foo3() {
18 undeclared();
19 }
Chandler Carruth03b77b32011-04-25 06:34:35 +000020};
21
22
23template <class T>
David Majnemerea5092a2013-07-07 23:49:50 +000024void B<T>::foo5() { // expected-error {{redefinition of 'foo5'}}
Chandler Carruth03b77b32011-04-25 06:34:35 +000025}
26
27template <class T>
28void A<T>::foo2() {
29 undeclared();
30}
31
32
33template <class T>
34void foo3() {
35 undeclared();
36}
37
38template void A<int>::foo2();
39
40
41void undeclared()
42{
43
44}
45
46template <class T> void foo5() {} //expected-note {{previous definition is here}}
47template <class T> void foo5() {} // expected-error {{redefinition of 'foo5'}}
Francois Pichet81345182011-09-22 22:14:56 +000048
49
50
Francois Pichete6664762012-02-22 08:25:53 +000051
52namespace PR11931 {
53
54template <typename RunType>
55struct BindState;
56
57 template<>
58struct BindState<void(void*)> {
59 static void Run() { }
60};
61
62class Callback {
63public:
64 typedef void RunType();
65
66 template <typename RunType>
67 Callback(BindState<RunType> bind_state) {
68 BindState<RunType>::Run();
69 }
70};
71
72
73Callback Bind() {
74 return Callback(BindState<void(void*)>());
75}
76
77}
Douglas Gregor1edf5762012-06-28 21:43:01 +000078
79namespace rdar11700604 {
80 template<typename T> void foo() = delete;
81
82 struct X {
83 X() = default;
84
85 template<typename T> void foo() = delete;
86 };
87}
88
David Majnemerc185aa72013-09-27 04:14:12 +000089namespace PR17334 {
90
91template <typename = void> struct ArrayRef {
92 constexpr ArrayRef() {}
93};
94template <typename = void> void CreateConstInBoundsGEP2_32() {
95 ArrayRef<> IdxList;
96}
97void LLVMBuildStructGEP() { CreateConstInBoundsGEP2_32(); }
98
99}
100
David Majnemerc85ed7e2013-10-23 21:31:20 +0000101namespace PR17661 {
102template <typename T>
103constexpr T Fun(T A) { return T(0); }
104
105constexpr int Var = Fun(20);
106}
107
Richard Smith8e6002f2014-03-12 23:14:33 +0000108template <typename T>
109auto invalidTrailingRetType() -> Bogus {} // expected-error {{unknown type name 'Bogus'}}
Hans Wennborgb6d4e8c2014-05-02 02:01:07 +0000110
111namespace PR19613 {
112
113struct HeapTypeConfig {
114 static void from_bitset();
115};
116
117template <class Config>
118struct TypeImpl {
119 struct BitsetType;
120
121 static void Any() {
122 BitsetType::New();
123 }
124};
125
126template<class Config>
127struct TypeImpl<Config>::BitsetType {
128 static void New() {
129 Config::from_bitset();
130 }
131};
132
133static void f() {
134 TypeImpl<HeapTypeConfig>::Any();
135}
136
137template<typename A> struct S {
138 template<typename B> struct T;
139};
140template<typename A> template<typename B> struct S<A>::T {
141 template<typename C, typename D> struct U;
142 template<typename C> struct U<C, C> {
143 template<typename E> static int f() {
144 return sizeof(A) + sizeof(B) + sizeof(C) + sizeof(E);
145 }
146 };
147};
148
149static void g() {
150 S<int>::T<int>::U<int,int>::f<int>();
151}
152
153template<typename T> struct SS {
154 template<typename U> struct X;
155 template<typename U> struct X<U*>;
156};
157template<typename T> template<typename U> struct SS<T>::X<U*> {
158 static int f() {
159 return sizeof(T) + sizeof(U);
160 }
161};
162
163static void h() {
164 SS<int>::X<int*>::f();
165}
166
167}
Reid Kleckner229eee42018-11-27 21:20:42 +0000168
169struct PR38460 {
170 template <typename>
171 struct T {
172 static void foo() {
173 struct U {
174 void dummy() {
175 use_delayed_identifier();
176 }
177 };
178 }
179 };
180};
181void use_delayed_identifier();
182void trigger_PR38460() {
183 PR38460::T<int>::foo();
184}
185
186template <typename> struct PR38460_2 {
187 struct p {
188 struct G {
189 bool operator()(int) {}
190 };
191 };
192 static void as() {
193 typename p::G g;
194 g(0);
195 }
196};
197template struct PR38460_2<int>;