Skip to content

Commit c787a57

Browse files
committed
[FOLD] add tests
1 parent a4865de commit c787a57

File tree

3 files changed

+348
-0
lines changed

3 files changed

+348
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %clang_cc1 -std=c++23 %s -verify
2+
3+
int f();
4+
5+
struct A {
6+
int B, C; // expected-note {{declared as a non-template here}}
7+
template<int> using D = void;
8+
using T = void;
9+
void f();
10+
};
11+
12+
using B = A;
13+
template<int> using C = A;
14+
template<int> using D = A;
15+
template<int> using X = A;
16+
17+
template<class T>
18+
void g(T *p) {
19+
p->X<0>::f(); // expected-error {{no member named 'X' in 'A'}}
20+
p->template X<0>::f();
21+
p->B::f();
22+
p->template C<0>::f(); // expected-error {{'C' following the 'template' keyword does not refer to a template}}
23+
p->template D<0>::f(); // expected-error {{type 'template D<0>' (aka 'void') cannot be used prior to '::' because it has no members}}
24+
p->T::f(); // expected-error {{'A::T' (aka 'void') is not a class, namespace, or enumeration}}
25+
}
26+
27+
template void g(A*); // expected-note {{in instantiation of}}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// RUN: %clang_cc1 -std=c++23 -Wno-unused %s -verify
2+
3+
struct A {
4+
int x;
5+
6+
template<typename T>
7+
using C = A;
8+
};
9+
10+
using B = A;
11+
12+
template<typename T>
13+
using D = A;
14+
15+
using E = void;
16+
17+
struct F : A {
18+
void non_template() {
19+
this->x;
20+
this->A::x;
21+
this->B::x;
22+
this->C<int>::x;
23+
this->D<int>::x;
24+
this->E::x; // expected-error {{'E' (aka 'void') is not a class, namespace, or enumeration}}
25+
}
26+
};
27+
28+
template<typename T>
29+
void not_instantiated(T t) {
30+
t.x;
31+
t.A::x;
32+
t.B::x;
33+
t.C<int>::x; // expected-error {{use 'template' keyword to treat 'C' as a dependent template name}}
34+
t.template C<int>::x;
35+
t.D<int>::x; // expected-error {{use 'template' keyword to treat 'D' as a dependent template name}}
36+
t.template D<int>::x;
37+
t.E::x;
38+
}
39+
40+
template<typename T>
41+
void instantiated_valid(T t) {
42+
t.x;
43+
t.A::x;
44+
t.B::x;
45+
t.template C<int>::x;
46+
t.template D<int>::x;
47+
t.E::x;
48+
}
49+
50+
template<typename T>
51+
void instantiated_invalid(T t) {
52+
t.x;
53+
t.A::x;
54+
t.B::x; // expected-error {{'Invalid::B' (aka 'void') is not a class, namespace, or enumeration}}
55+
t.template C<int>::x;
56+
t.template D<int>::x; // expected-error {{'D' following the 'template' keyword does not refer to a template}}
57+
t.E::x; // expected-error {{'E' (aka 'void') is not a class, namespace, or enumeration}}
58+
}
59+
60+
struct Valid : A {
61+
using E = A;
62+
};
63+
64+
template void instantiated_valid(Valid);
65+
66+
struct Invalid : A {
67+
using B = void;
68+
using D = A; // expected-note {{declared as a non-template here}}
69+
};
70+
71+
template void instantiated_invalid(Invalid); // expected-note {{in instantiation of}}
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
// RUN: %clang_cc1 -std=c++23 %s -verify
2+
3+
namespace FoundNothing {
4+
template<typename T>
5+
void f0(T &t) {
6+
t.x<0;
7+
t.x<0>; // expected-error {{expected expression}}
8+
t.x<0>1;
9+
}
10+
11+
template<typename T>
12+
struct A {
13+
void f1() {
14+
this->x<0; // expected-error {{no member named 'x' in 'A<T>'}}
15+
this->x<0>; // expected-error {{expected expression}}
16+
// expected-error@-1 {{no member named 'x' in 'A<T>'}}
17+
this->x<0>1; // expected-error {{no member named 'x' in 'A<T>'}}
18+
}
19+
};
20+
} // namespace FoundNothing
21+
22+
namespace FoundSingleNonTemplate {
23+
void f0();
24+
25+
struct A0;
26+
27+
template<typename T>
28+
void g0(T &t) {
29+
t.f0<0;
30+
t.f0<0>; // expected-error {{expected expression}}
31+
t.f0<0> 1;
32+
33+
t.A0<0;
34+
t.A0<0>; // expected-error {{expected expression}}
35+
t.A0<0>1;
36+
}
37+
38+
template<typename T>
39+
struct B {
40+
void f1();
41+
42+
struct A1; // expected-note 3{{member 'A1' declared here}}
43+
44+
void g1() {
45+
this->f0<0; // expected-error {{no member named 'f0' in 'B<T>'}}
46+
this->f0<0>; // expected-error {{expected expression}}
47+
// expected-error@-1 {{no member named 'f0' in 'B<T>'}}
48+
this->f0<0>1; // expected-error {{no member named 'f0' in 'B<T>'}}
49+
50+
this->A0<0; // expected-error {{no member named 'A0' in 'B<T>'}}
51+
this->A0<0>; // expected-error {{expected expression}}
52+
// expected-error@-1 {{no member named 'A0' in 'B<T>'}}
53+
this->A0<0>1; // expected-error {{no member named 'A0' in 'B<T>'}}
54+
55+
this->f1<0; // expected-error {{reference to non-static member function must be called}}
56+
this->f1<0>; // expected-error {{expected expression}}
57+
// expected-error@-1 {{reference to non-static member function must be called}}
58+
this->f1<0>1; // expected-error {{reference to non-static member function must be called}}
59+
60+
this->A1<0; // expected-error {{cannot refer to type member 'A1' in 'B<T>' with '->'}}
61+
this->A1<0>; // expected-error {{expected expression}}
62+
// expected-error@-1 {{cannot refer to type member 'A1' in 'B<T>' with '->'}}
63+
this->A1<0>1; // expected-error {{cannot refer to type member 'A1' in 'B<T>' with '->'}}
64+
}
65+
};
66+
} // namespace FoundSingleNonTemplate
67+
68+
namespace FoundSingleTemplate {
69+
template<int I>
70+
void f0();
71+
72+
template<int I>
73+
struct A0;
74+
75+
template<typename T>
76+
void g0(T &t) {
77+
t.f0<0;
78+
t.f0<0>; // expected-error {{expected expression}}
79+
t.f0<0>1;
80+
81+
t.A0<0;
82+
t.A0<0>; // expected-error {{expected expression}}
83+
t.A0<0>1;
84+
}
85+
86+
template<typename T>
87+
struct B {
88+
template<int I>
89+
void f1(); // expected-note 2{{possible target for call}}
90+
91+
template<int I>
92+
struct A1; // expected-note 2{{member 'A1' declared here}}
93+
94+
void g1() {
95+
this->f0<0; // expected-error {{expected '>'}}
96+
// expected-note@-1 {{to match this '<'}}
97+
// expected-error@-2 {{expected unqualified-id}}
98+
this->f0<0>; // expected-error {{no member named 'f0' in 'B<T>'}}
99+
this->f0<0>1; // expected-error {{no member named 'f0' in 'B<T>'}}
100+
// expected-error@-1 {{expected ';' after expression}}
101+
102+
this->A0<0; // expected-error {{expected '>'}}
103+
// expected-note@-1 {{to match this '<'}}
104+
// expected-error@-2 {{expected unqualified-id}}
105+
this->A0<0>; // expected-error {{no member named 'A0' in 'B<T>'}}
106+
this->A0<0>1; // expected-error {{no member named 'A0' in 'B<T>'}}
107+
// expected-error@-1 {{expected ';' after expression}}
108+
109+
110+
this->f1<0; // expected-error {{expected '>'}}
111+
// expected-note@-1 {{to match this '<'}}
112+
// expected-error@-2 {{expected unqualified-id}}
113+
this->f1<0>; // expected-error {{reference to non-static member function must be called}}
114+
this->f1<0>1; // expected-error {{reference to non-static member function must be called}}
115+
// expected-error@-1 {{expected ';' after expression}}
116+
117+
this->A1<0; // expected-error {{expected '>'}}
118+
// expected-note@-1 {{to match this '<'}}
119+
// expected-error@-2 {{expected unqualified-id}}
120+
this->A1<0>; // expected-error {{cannot refer to member 'A1' in 'B<T>' with '->'}}
121+
this->A1<0>1; // expected-error {{cannot refer to member 'A1' in 'B<T>' with '->'}}
122+
// expected-error@-1 {{expected ';' after expression}}
123+
}
124+
};
125+
} // namespace FoundSingleTemplate
126+
127+
namespace FoundAmbiguousNonTemplate {
128+
inline namespace N {
129+
int f0;
130+
131+
struct A0;
132+
} // namespace N
133+
134+
void f0();
135+
136+
struct A0;
137+
138+
template<typename T>
139+
void g0(T &t) {
140+
t.f0<0;
141+
t.f0<0>; // expected-error {{expected expression}}
142+
t.f0<0>1;
143+
144+
t.A0<0;
145+
t.A0<0>; // expected-error {{expected expression}}
146+
t.A0<0>1;
147+
}
148+
149+
template<typename T>
150+
struct B {
151+
void f1();
152+
153+
struct A1; // expected-note 3{{member 'A1' declared here}}
154+
155+
void g1() {
156+
this->f0<0; // expected-error {{no member named 'f0' in 'B<T>'}}
157+
this->f0<0>; // expected-error {{expected expression}}
158+
// expected-error@-1 {{no member named 'f0' in 'B<T>'}}
159+
this->f0<0>1; // expected-error {{no member named 'f0' in 'B<T>'}}
160+
161+
this->A0<0; // expected-error {{no member named 'A0' in 'B<T>'}}
162+
this->A0<0>; // expected-error {{expected expression}}
163+
// expected-error@-1 {{no member named 'A0' in 'B<T>'}}
164+
this->A0<0>1; // expected-error {{no member named 'A0' in 'B<T>'}}
165+
166+
this->f1<0; // expected-error {{reference to non-static member function must be called}}
167+
this->f1<0>; // expected-error {{expected expression}}
168+
// expected-error@-1 {{reference to non-static member function must be called}}
169+
this->f1<0>1; // expected-error {{reference to non-static member function must be called}}
170+
171+
this->A1<0; // expected-error {{cannot refer to type member 'A1' in 'B<T>' with '->'}}
172+
this->A1<0>; // expected-error {{expected expression}}
173+
// expected-error@-1 {{cannot refer to type member 'A1' in 'B<T>' with '->'}}
174+
this->A1<0>1; // expected-error {{cannot refer to type member 'A1' in 'B<T>' with '->'}}
175+
}
176+
};
177+
} // namespace FoundAmbiguousNonTemplates
178+
179+
namespace FoundAmbiguousTemplate {
180+
inline namespace N {
181+
template<int I>
182+
int f0; // expected-note 3{{candidate found by name lookup is 'FoundAmbiguousTemplate::N::f0'}}
183+
184+
template<int I>
185+
struct A0; // expected-note 3{{candidate found by name lookup is 'FoundAmbiguousTemplate::N::A0'}}
186+
} // namespace N
187+
188+
template<int I>
189+
void f0(); // expected-note 3{{candidate found by name lookup is 'FoundAmbiguousTemplate::f0'}}
190+
191+
template<int I>
192+
struct A0; // expected-note 3{{candidate found by name lookup is 'FoundAmbiguousTemplate::A0'}}
193+
194+
template<typename T>
195+
void g0(T &t) {
196+
t.f0<0;
197+
t.f0<0>; // expected-error {{expected expression}}
198+
t.f0<0>1;
199+
200+
t.A0<0;
201+
t.A0<0>; // expected-error {{expected expression}}
202+
t.A0<0>1;
203+
}
204+
205+
template<typename T>
206+
struct B {
207+
template<int I>
208+
void f1(); // expected-note 2{{possible target for call}}
209+
210+
template<int I>
211+
struct A1; // expected-note 2{{member 'A1' declared here}}
212+
213+
void g1() {
214+
this->f0<0; // expected-error {{expected '>'}}
215+
// expected-note@-1 {{to match this '<'}}
216+
// expected-error@-2 {{expected unqualified-id}}
217+
// expected-error@-3 {{reference to 'f0' is ambiguous}}
218+
this->f0<0>; // expected-error {{no member named 'f0' in 'B<T>'}}
219+
// expected-error@-1 {{reference to 'f0' is ambiguous}}
220+
this->f0<0>1; // expected-error {{no member named 'f0' in 'B<T>'}}
221+
// expected-error@-1 {{expected ';' after expression}}
222+
// expected-error@-2 {{reference to 'f0' is ambiguous}}
223+
224+
this->A0<0; // expected-error {{expected '>'}}
225+
// expected-note@-1 {{to match this '<'}}
226+
// expected-error@-2 {{expected unqualified-id}}
227+
// expected-error@-3 {{reference to 'A0' is ambiguous}}
228+
this->A0<0>; // expected-error {{no member named 'A0' in 'B<T>'}}
229+
// expected-error@-1 {{reference to 'A0' is ambiguous}}
230+
this->A0<0>1; // expected-error {{no member named 'A0' in 'B<T>'}}
231+
// expected-error@-1 {{expected ';' after expression}}
232+
// expected-error@-2 {{reference to 'A0' is ambiguous}}
233+
234+
235+
this->f1<0; // expected-error {{expected '>'}}
236+
// expected-note@-1 {{to match this '<'}}
237+
// expected-error@-2 {{expected unqualified-id}}
238+
this->f1<0>; // expected-error {{reference to non-static member function must be called}}
239+
this->f1<0>1; // expected-error {{reference to non-static member function must be called}}
240+
// expected-error@-1 {{expected ';' after expression}}
241+
242+
this->A1<0; // expected-error {{expected '>'}}
243+
// expected-note@-1 {{to match this '<'}}
244+
// expected-error@-2 {{expected unqualified-id}}
245+
this->A1<0>; // expected-error {{cannot refer to member 'A1' in 'B<T>' with '->'}}
246+
this->A1<0>1; // expected-error {{cannot refer to member 'A1' in 'B<T>' with '->'}}
247+
// expected-error@-1 {{expected ';' after expression}}
248+
}
249+
};
250+
} // namespace FoundAmbiguousTemplate

0 commit comments

Comments
 (0)