1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -std=c++1y -fms-compatibility -fno-spell-checking -fsyntax-only -verify %s
2f4a2713aSLionel Sambuc
3f4a2713aSLionel Sambuc
4f4a2713aSLionel Sambuc template <class T>
5f4a2713aSLionel Sambuc class A {
6f4a2713aSLionel Sambuc public:
f(T a)7f4a2713aSLionel Sambuc void f(T a) { }// expected-note {{must qualify identifier to find this declaration in dependent base class}}
8f4a2713aSLionel Sambuc void g();// expected-note {{must qualify identifier to find this declaration in dependent base class}}
9f4a2713aSLionel Sambuc };
10f4a2713aSLionel Sambuc
11f4a2713aSLionel Sambuc template <class T>
12f4a2713aSLionel Sambuc class B : public A<T> {
13f4a2713aSLionel Sambuc public:
z(T a)14f4a2713aSLionel Sambuc void z(T a)
15f4a2713aSLionel Sambuc {
16f4a2713aSLionel Sambuc f(a); // expected-warning {{use of identifier 'f' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
17f4a2713aSLionel Sambuc g(); // expected-warning {{use of identifier 'g' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
18f4a2713aSLionel Sambuc }
19f4a2713aSLionel Sambuc };
20f4a2713aSLionel Sambuc
21f4a2713aSLionel Sambuc template class B<int>; // expected-note {{requested here}}
22f4a2713aSLionel Sambuc template class B<char>;
23f4a2713aSLionel Sambuc
test()24f4a2713aSLionel Sambuc void test()
25f4a2713aSLionel Sambuc {
26f4a2713aSLionel Sambuc B<int> b;
27f4a2713aSLionel Sambuc b.z(3);
28f4a2713aSLionel Sambuc }
29f4a2713aSLionel Sambuc
30f4a2713aSLionel Sambuc struct A2 {
fA231f4a2713aSLionel Sambuc template<class T> void f(T) {
32f4a2713aSLionel Sambuc XX; //expected-error {{use of undeclared identifier 'XX'}}
33f4a2713aSLionel Sambuc A2::XX; //expected-error {{no member named 'XX' in 'A2'}}
34f4a2713aSLionel Sambuc }
35f4a2713aSLionel Sambuc };
36f4a2713aSLionel Sambuc template void A2::f(int);
37f4a2713aSLionel Sambuc
38f4a2713aSLionel Sambuc template<class T0>
39f4a2713aSLionel Sambuc struct A3 {
fA340f4a2713aSLionel Sambuc template<class T1> void f(T1) {
41f4a2713aSLionel Sambuc XX; //expected-error {{use of undeclared identifier 'XX'}}
42f4a2713aSLionel Sambuc }
43f4a2713aSLionel Sambuc };
44f4a2713aSLionel Sambuc template void A3<int>::f(int);
45f4a2713aSLionel Sambuc
46f4a2713aSLionel Sambuc template<class T0>
47f4a2713aSLionel Sambuc struct A4 {
fA448f4a2713aSLionel Sambuc void f(char) {
49f4a2713aSLionel Sambuc XX; //expected-error {{use of undeclared identifier 'XX'}}
50f4a2713aSLionel Sambuc }
51f4a2713aSLionel Sambuc };
52f4a2713aSLionel Sambuc template class A4<int>;
53f4a2713aSLionel Sambuc
54f4a2713aSLionel Sambuc
55f4a2713aSLionel Sambuc namespace lookup_dependent_bases_id_expr {
56f4a2713aSLionel Sambuc
57f4a2713aSLionel Sambuc template<class T> class A {
58f4a2713aSLionel Sambuc public:
59f4a2713aSLionel Sambuc int var;
60f4a2713aSLionel Sambuc };
61f4a2713aSLionel Sambuc
62f4a2713aSLionel Sambuc
63f4a2713aSLionel Sambuc template<class T>
64f4a2713aSLionel Sambuc class B : public A<T> {
65f4a2713aSLionel Sambuc public:
f()66f4a2713aSLionel Sambuc void f() {
67*0a6a1f1dSLionel Sambuc var = 3; // expected-warning {{use of undeclared identifier 'var'; unqualified lookup into dependent bases of class template 'B' is a Microsoft extension}}
68f4a2713aSLionel Sambuc }
69f4a2713aSLionel Sambuc };
70f4a2713aSLionel Sambuc
71f4a2713aSLionel Sambuc template class B<int>;
72f4a2713aSLionel Sambuc
73f4a2713aSLionel Sambuc }
74f4a2713aSLionel Sambuc
75f4a2713aSLionel Sambuc
76f4a2713aSLionel Sambuc
77f4a2713aSLionel Sambuc namespace lookup_dependent_base_class_static_function {
78f4a2713aSLionel Sambuc
79f4a2713aSLionel Sambuc template <class T>
80f4a2713aSLionel Sambuc class A {
81f4a2713aSLionel Sambuc public:
82f4a2713aSLionel Sambuc static void static_func();// expected-note {{must qualify identifier to find this declaration in dependent base class}}
83f4a2713aSLionel Sambuc void func();// expected-note {{must qualify identifier to find this declaration in dependent base class}}
84f4a2713aSLionel Sambuc };
85f4a2713aSLionel Sambuc
86f4a2713aSLionel Sambuc
87f4a2713aSLionel Sambuc template <class T>
88f4a2713aSLionel Sambuc class B : public A<T> {
89f4a2713aSLionel Sambuc public:
z2()90f4a2713aSLionel Sambuc static void z2(){
91f4a2713aSLionel Sambuc static_func(); // expected-warning {{use of identifier 'static_func' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
92f4a2713aSLionel Sambuc func(); // expected-warning {{use of identifier 'func' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} expected-error {{call to non-static member function without an object argument}}
93f4a2713aSLionel Sambuc }
94f4a2713aSLionel Sambuc };
95f4a2713aSLionel Sambuc template class B<int>; // expected-note {{requested here}}
96f4a2713aSLionel Sambuc
97f4a2713aSLionel Sambuc }
98f4a2713aSLionel Sambuc
99f4a2713aSLionel Sambuc
100f4a2713aSLionel Sambuc
101f4a2713aSLionel Sambuc namespace lookup_dependent_base_class_default_argument {
102f4a2713aSLionel Sambuc
103f4a2713aSLionel Sambuc template<class T>
104f4a2713aSLionel Sambuc class A {
105f4a2713aSLionel Sambuc public:
106f4a2713aSLionel Sambuc static int f1(); // expected-note {{must qualify identifier to find this declaration in dependent base class}}
107f4a2713aSLionel Sambuc int f2(); // expected-note {{must qualify identifier to find this declaration in dependent base class}}
108f4a2713aSLionel Sambuc };
109f4a2713aSLionel Sambuc
110f4a2713aSLionel Sambuc template<class T>
111f4a2713aSLionel Sambuc class B : public A<T> {
112f4a2713aSLionel Sambuc public:
113f4a2713aSLionel Sambuc void g1(int p = f1());// expected-warning {{use of identifier 'f1' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
114f4a2713aSLionel Sambuc void g2(int p = f2());// expected-warning {{use of identifier 'f2' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} expected-error {{call to non-static member function without an object argument}}
115f4a2713aSLionel Sambuc };
116f4a2713aSLionel Sambuc
foo()117f4a2713aSLionel Sambuc void foo()
118f4a2713aSLionel Sambuc {
119f4a2713aSLionel Sambuc B<int> b;
120f4a2713aSLionel Sambuc b.g1(); // expected-note {{required here}}
121f4a2713aSLionel Sambuc b.g2(); // expected-note {{required here}}
122f4a2713aSLionel Sambuc }
123f4a2713aSLionel Sambuc
124f4a2713aSLionel Sambuc }
125f4a2713aSLionel Sambuc
126f4a2713aSLionel Sambuc
127f4a2713aSLionel Sambuc namespace lookup_dependent_base_class_friend {
128f4a2713aSLionel Sambuc
129f4a2713aSLionel Sambuc template <class T>
130f4a2713aSLionel Sambuc class B {
131f4a2713aSLionel Sambuc public:
132f4a2713aSLionel Sambuc static void g(); // expected-note {{must qualify identifier to find this declaration in dependent base class}}
133f4a2713aSLionel Sambuc };
134f4a2713aSLionel Sambuc
135f4a2713aSLionel Sambuc template <class T>
136f4a2713aSLionel Sambuc class A : public B<T> {
137f4a2713aSLionel Sambuc public:
foo(A<T> p)138f4a2713aSLionel Sambuc friend void foo(A<T> p){
139f4a2713aSLionel Sambuc g(); // expected-warning {{use of identifier 'g' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
140f4a2713aSLionel Sambuc }
141f4a2713aSLionel Sambuc };
142f4a2713aSLionel Sambuc
main2()143f4a2713aSLionel Sambuc int main2()
144f4a2713aSLionel Sambuc {
145f4a2713aSLionel Sambuc A<int> a;
146f4a2713aSLionel Sambuc foo(a); // expected-note {{requested here}}
147f4a2713aSLionel Sambuc }
148f4a2713aSLionel Sambuc
149f4a2713aSLionel Sambuc }
150f4a2713aSLionel Sambuc
151f4a2713aSLionel Sambuc
152f4a2713aSLionel Sambuc namespace lookup_dependent_base_no_typo_correction {
153f4a2713aSLionel Sambuc
154f4a2713aSLionel Sambuc class C {
155f4a2713aSLionel Sambuc public:
156f4a2713aSLionel Sambuc int m_hWnd;
157f4a2713aSLionel Sambuc };
158f4a2713aSLionel Sambuc
159f4a2713aSLionel Sambuc template <class T>
160f4a2713aSLionel Sambuc class A : public T {
161f4a2713aSLionel Sambuc public:
f(int hWnd)162f4a2713aSLionel Sambuc void f(int hWnd) {
163*0a6a1f1dSLionel Sambuc m_hWnd = 1; // expected-warning {{use of undeclared identifier 'm_hWnd'; unqualified lookup into dependent bases of class template 'A' is a Microsoft extension}}
164f4a2713aSLionel Sambuc }
165f4a2713aSLionel Sambuc };
166f4a2713aSLionel Sambuc
167f4a2713aSLionel Sambuc template class A<C>;
168f4a2713aSLionel Sambuc
169f4a2713aSLionel Sambuc }
170f4a2713aSLionel Sambuc
171f4a2713aSLionel Sambuc namespace PR12701 {
172f4a2713aSLionel Sambuc
173f4a2713aSLionel Sambuc class A {};
174f4a2713aSLionel Sambuc class B {};
175f4a2713aSLionel Sambuc
176f4a2713aSLionel Sambuc template <class T>
177f4a2713aSLionel Sambuc class Base {
178f4a2713aSLionel Sambuc public:
base_fun(void * p)179*0a6a1f1dSLionel Sambuc bool base_fun(void* p) { return false; } // expected-note {{must qualify identifier to find this declaration in dependent base class}}
operator T*() const180f4a2713aSLionel Sambuc operator T*() const { return 0; }
181f4a2713aSLionel Sambuc };
182f4a2713aSLionel Sambuc
183f4a2713aSLionel Sambuc template <class T>
184f4a2713aSLionel Sambuc class Container : public Base<T> {
185f4a2713aSLionel Sambuc public:
186f4a2713aSLionel Sambuc template <typename S>
operator =(const Container<S> & rhs)187f4a2713aSLionel Sambuc bool operator=(const Container<S>& rhs) {
188f4a2713aSLionel Sambuc return base_fun(rhs); // expected-warning {{use of identifier 'base_fun' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
189f4a2713aSLionel Sambuc }
190f4a2713aSLionel Sambuc };
191f4a2713aSLionel Sambuc
f()192f4a2713aSLionel Sambuc void f() {
193f4a2713aSLionel Sambuc Container<A> text_provider;
194f4a2713aSLionel Sambuc Container<B> text_provider2;
195f4a2713aSLionel Sambuc text_provider2 = text_provider; // expected-note {{in instantiation of function template specialization}}
196f4a2713aSLionel Sambuc }
197f4a2713aSLionel Sambuc
198f4a2713aSLionel Sambuc } // namespace PR12701
199f4a2713aSLionel Sambuc
200f4a2713aSLionel Sambuc namespace PR16014 {
201f4a2713aSLionel Sambuc
202f4a2713aSLionel Sambuc struct A {
203f4a2713aSLionel Sambuc int a;
204f4a2713aSLionel Sambuc static int sa;
205f4a2713aSLionel Sambuc };
206f4a2713aSLionel Sambuc template <typename T> struct B : T {
fooPR16014::B207*0a6a1f1dSLionel Sambuc int foo() { return a; } // expected-warning {{lookup into dependent bases}}
barPR16014::B208*0a6a1f1dSLionel Sambuc int *bar() { return &a; } // expected-warning {{lookup into dependent bases}}
bazPR16014::B209f4a2713aSLionel Sambuc int baz() { return T::a; }
quxPR16014::B210f4a2713aSLionel Sambuc int T::*qux() { return &T::a; }
stuffPR16014::B211f4a2713aSLionel Sambuc static int T::*stuff() { return &T::a; }
stuff1PR16014::B212f4a2713aSLionel Sambuc static int stuff1() { return T::sa; }
stuff2PR16014::B213f4a2713aSLionel Sambuc static int *stuff2() { return &T::sa; }
stuff3PR16014::B214*0a6a1f1dSLionel Sambuc static int stuff3() { return sa; } // expected-warning {{lookup into dependent bases}}
stuff4PR16014::B215*0a6a1f1dSLionel Sambuc static int *stuff4() { return &sa; } // expected-warning {{lookup into dependent bases}}
216f4a2713aSLionel Sambuc };
217f4a2713aSLionel Sambuc
218f4a2713aSLionel Sambuc template <typename T> struct C : T {
fooPR16014::C219*0a6a1f1dSLionel Sambuc int foo() { return b; } // expected-error {{no member named 'b' in 'PR16014::C<PR16014::A>'}} expected-warning {{lookup into dependent bases}}
barPR16014::C220*0a6a1f1dSLionel Sambuc int *bar() { return &b; } // expected-error {{no member named 'b' in 'PR16014::C<PR16014::A>'}} expected-warning {{lookup into dependent bases}}
bazPR16014::C221f4a2713aSLionel Sambuc int baz() { return T::b; } // expected-error {{no member named 'b' in 'PR16014::A'}}
quxPR16014::C222f4a2713aSLionel Sambuc int T::*qux() { return &T::b; } // expected-error {{no member named 'b' in 'PR16014::A'}}
fuzPR16014::C223*0a6a1f1dSLionel Sambuc int T::*fuz() { return &U::a; } // expected-error {{use of undeclared identifier 'U'}} \
224*0a6a1f1dSLionel Sambuc // expected-warning {{unqualified lookup into dependent bases of class template 'C'}}
225f4a2713aSLionel Sambuc };
226f4a2713aSLionel Sambuc
227f4a2713aSLionel Sambuc template struct B<A>;
228*0a6a1f1dSLionel Sambuc template struct C<A>; // expected-note-re 1+ {{in instantiation of member function 'PR16014::C<PR16014::A>::{{.*}}' requested here}}
229f4a2713aSLionel Sambuc
230f4a2713aSLionel Sambuc template <typename T> struct D : T {
231f4a2713aSLionel Sambuc struct Inner {
fooPR16014::D::Inner232f4a2713aSLionel Sambuc int foo() {
233f4a2713aSLionel Sambuc // FIXME: MSVC can find this in D's base T! Even worse, if ::sa exists,
234f4a2713aSLionel Sambuc // clang will use it instead.
235f4a2713aSLionel Sambuc return sa; // expected-error {{use of undeclared identifier 'sa'}}
236f4a2713aSLionel Sambuc }
237f4a2713aSLionel Sambuc };
238f4a2713aSLionel Sambuc };
239f4a2713aSLionel Sambuc template struct D<A>;
240f4a2713aSLionel Sambuc
241f4a2713aSLionel Sambuc }
242*0a6a1f1dSLionel Sambuc
243*0a6a1f1dSLionel Sambuc namespace PR19233 {
244*0a6a1f1dSLionel Sambuc template <class T>
245*0a6a1f1dSLionel Sambuc struct A : T {
fooPR19233::A246*0a6a1f1dSLionel Sambuc void foo() {
247*0a6a1f1dSLionel Sambuc ::undef(); // expected-error {{no member named 'undef' in the global namespace}}
248*0a6a1f1dSLionel Sambuc }
barPR19233::A249*0a6a1f1dSLionel Sambuc void bar() {
250*0a6a1f1dSLionel Sambuc ::UndefClass::undef(); // expected-error {{no member named 'UndefClass' in the global namespace}}
251*0a6a1f1dSLionel Sambuc }
bazPR19233::A252*0a6a1f1dSLionel Sambuc void baz() {
253*0a6a1f1dSLionel Sambuc B::qux(); // expected-error {{use of undeclared identifier 'B'}} \
254*0a6a1f1dSLionel Sambuc // expected-warning {{unqualified lookup into dependent bases of class template 'A'}}
255*0a6a1f1dSLionel Sambuc }
256*0a6a1f1dSLionel Sambuc };
257*0a6a1f1dSLionel Sambuc
258*0a6a1f1dSLionel Sambuc struct B { void qux(); };
259*0a6a1f1dSLionel Sambuc struct C : B { };
260*0a6a1f1dSLionel Sambuc template struct A<C>; // No error! B is a base of A<C>, and qux is available.
261*0a6a1f1dSLionel Sambuc
262*0a6a1f1dSLionel Sambuc struct D { };
263*0a6a1f1dSLionel Sambuc template struct A<D>; // expected-note {{in instantiation of member function 'PR19233::A<PR19233::D>::baz' requested here}}
264*0a6a1f1dSLionel Sambuc
265*0a6a1f1dSLionel Sambuc }
266*0a6a1f1dSLionel Sambuc
267*0a6a1f1dSLionel Sambuc namespace nonmethod_missing_this {
268*0a6a1f1dSLionel Sambuc template <typename T> struct Base { int y = 42; };
269*0a6a1f1dSLionel Sambuc template <typename T> struct Derived : Base<T> {
270*0a6a1f1dSLionel Sambuc int x = y; // expected-warning {{lookup into dependent bases}}
foononmethod_missing_this::Derived271*0a6a1f1dSLionel Sambuc auto foo(int j) -> decltype(y * j) { // expected-warning {{lookup into dependent bases}}
272*0a6a1f1dSLionel Sambuc return y * j; // expected-warning {{lookup into dependent bases}}
273*0a6a1f1dSLionel Sambuc }
barnonmethod_missing_this::Derived274*0a6a1f1dSLionel Sambuc int bar() {
275*0a6a1f1dSLionel Sambuc return [&] { return y; }(); // expected-warning {{lookup into dependent bases}}
276*0a6a1f1dSLionel Sambuc }
277*0a6a1f1dSLionel Sambuc };
278*0a6a1f1dSLionel Sambuc template struct Derived<int>;
279*0a6a1f1dSLionel Sambuc }
280*0a6a1f1dSLionel Sambuc
281*0a6a1f1dSLionel Sambuc namespace typedef_in_base {
282*0a6a1f1dSLionel Sambuc template <typename T> struct A { typedef T NameFromBase; };
283*0a6a1f1dSLionel Sambuc template <typename T> struct B : A<T> {
284*0a6a1f1dSLionel Sambuc NameFromBase m; // expected-warning {{found via unqualified lookup into dependent bases}}
285*0a6a1f1dSLionel Sambuc };
286*0a6a1f1dSLionel Sambuc static_assert(sizeof(B<int>) == 4, "");
287*0a6a1f1dSLionel Sambuc }
288*0a6a1f1dSLionel Sambuc
289*0a6a1f1dSLionel Sambuc namespace struct_in_base {
290*0a6a1f1dSLionel Sambuc template <typename T> struct A { struct NameFromBase {}; };
291*0a6a1f1dSLionel Sambuc template <typename T> struct B : A<T> {
292*0a6a1f1dSLionel Sambuc NameFromBase m; // expected-warning {{found via unqualified lookup into dependent bases}}
293*0a6a1f1dSLionel Sambuc };
294*0a6a1f1dSLionel Sambuc static_assert(sizeof(B<int>) == 1, "");
295*0a6a1f1dSLionel Sambuc }
296*0a6a1f1dSLionel Sambuc
297*0a6a1f1dSLionel Sambuc namespace enum_in_base {
298*0a6a1f1dSLionel Sambuc template <typename T> struct A { enum NameFromBase { X }; };
299*0a6a1f1dSLionel Sambuc template <typename T> struct B : A<T> {
300*0a6a1f1dSLionel Sambuc NameFromBase m; // expected-warning {{found via unqualified lookup into dependent bases}}
301*0a6a1f1dSLionel Sambuc };
302*0a6a1f1dSLionel Sambuc static_assert(sizeof(B<int>) == sizeof(A<int>::NameFromBase), "");
303*0a6a1f1dSLionel Sambuc }
304*0a6a1f1dSLionel Sambuc
305*0a6a1f1dSLionel Sambuc namespace two_types_in_base {
306*0a6a1f1dSLionel Sambuc template <typename T> struct A { typedef T NameFromBase; };
307*0a6a1f1dSLionel Sambuc template <typename T> struct B { struct NameFromBase { T m; }; };
308*0a6a1f1dSLionel Sambuc template <typename T> struct C : A<T>, B<T> {
309*0a6a1f1dSLionel Sambuc NameFromBase m; // expected-error {{unknown type name 'NameFromBase'}}
310*0a6a1f1dSLionel Sambuc };
311*0a6a1f1dSLionel Sambuc static_assert(sizeof(C<int>) == 4, "");
312*0a6a1f1dSLionel Sambuc }
313*0a6a1f1dSLionel Sambuc
314*0a6a1f1dSLionel Sambuc namespace type_and_decl_in_base {
315*0a6a1f1dSLionel Sambuc template <typename T> struct A { typedef T NameFromBase; };
316*0a6a1f1dSLionel Sambuc template <typename T> struct B { static const T NameFromBase = 42; };
317*0a6a1f1dSLionel Sambuc template <typename T> struct C : A<T>, B<T> {
318*0a6a1f1dSLionel Sambuc NameFromBase m; // expected-error {{unknown type name 'NameFromBase'}}
319*0a6a1f1dSLionel Sambuc };
320*0a6a1f1dSLionel Sambuc }
321*0a6a1f1dSLionel Sambuc
322*0a6a1f1dSLionel Sambuc namespace classify_type_from_base {
323*0a6a1f1dSLionel Sambuc template <typename T> struct A { struct NameFromBase {}; };
324*0a6a1f1dSLionel Sambuc template <typename T> struct B : A<T> {
325*0a6a1f1dSLionel Sambuc A<NameFromBase> m; // expected-warning {{found via unqualified lookup into dependent bases}}
326*0a6a1f1dSLionel Sambuc };
327*0a6a1f1dSLionel Sambuc }
328*0a6a1f1dSLionel Sambuc
329*0a6a1f1dSLionel Sambuc namespace classify_nontype_from_base {
330*0a6a1f1dSLionel Sambuc // MSVC does not do lookup of non-type declarations from dependent template base
331*0a6a1f1dSLionel Sambuc // classes. The extra lookup only applies to types.
NameFromBaseclassify_nontype_from_base::A332*0a6a1f1dSLionel Sambuc template <typename T> struct A { void NameFromBase() {} };
333*0a6a1f1dSLionel Sambuc template <void (*F)()> struct B { };
334*0a6a1f1dSLionel Sambuc template <typename T> struct C : A<T> {
335*0a6a1f1dSLionel Sambuc B<C::NameFromBase> a; // correct
336*0a6a1f1dSLionel Sambuc B<NameFromBase> b; // expected-error {{use of undeclared identifier 'NameFromBase'}}
337*0a6a1f1dSLionel Sambuc };
338*0a6a1f1dSLionel Sambuc }
339*0a6a1f1dSLionel Sambuc
340*0a6a1f1dSLionel Sambuc namespace template_in_base {
341*0a6a1f1dSLionel Sambuc template <typename T> struct A {
342*0a6a1f1dSLionel Sambuc template <typename U> struct NameFromBase { U x; };
343*0a6a1f1dSLionel Sambuc };
344*0a6a1f1dSLionel Sambuc template <typename T> struct B : A<T> {
345*0a6a1f1dSLionel Sambuc // Correct form.
346*0a6a1f1dSLionel Sambuc typename B::template NameFromBase<T> m;
347*0a6a1f1dSLionel Sambuc };
348*0a6a1f1dSLionel Sambuc template <typename T> struct C : A<T> {
349*0a6a1f1dSLionel Sambuc // Incorrect form.
350*0a6a1f1dSLionel Sambuc NameFromBase<T> m; // expected-error {{unknown type name 'NameFromBase'}}
351*0a6a1f1dSLionel Sambuc //expected-error@-1 {{expected member name or ';' after declaration specifiers}}
352*0a6a1f1dSLionel Sambuc };
353*0a6a1f1dSLionel Sambuc }
354*0a6a1f1dSLionel Sambuc
355*0a6a1f1dSLionel Sambuc namespace type_in_inner_class_in_base {
356*0a6a1f1dSLionel Sambuc template <typename T>
357*0a6a1f1dSLionel Sambuc struct A {
358*0a6a1f1dSLionel Sambuc struct B { typedef T NameFromBase; };
359*0a6a1f1dSLionel Sambuc };
360*0a6a1f1dSLionel Sambuc template <typename T>
361*0a6a1f1dSLionel Sambuc struct C : A<T>::B { NameFromBase m; }; // expected-error {{unknown type name 'NameFromBase'}}
362*0a6a1f1dSLionel Sambuc }
363*0a6a1f1dSLionel Sambuc
364*0a6a1f1dSLionel Sambuc namespace type_in_inner_template_class_in_base {
365*0a6a1f1dSLionel Sambuc template <typename T>
366*0a6a1f1dSLionel Sambuc struct A {
367*0a6a1f1dSLionel Sambuc template <typename U> struct B { typedef U InnerType; };
368*0a6a1f1dSLionel Sambuc };
369*0a6a1f1dSLionel Sambuc template <typename T>
370*0a6a1f1dSLionel Sambuc struct C : A<T>::template B<T> {
371*0a6a1f1dSLionel Sambuc NameFromBase m; // expected-error {{unknown type name 'NameFromBase'}}
372*0a6a1f1dSLionel Sambuc };
373*0a6a1f1dSLionel Sambuc }
374*0a6a1f1dSLionel Sambuc
375*0a6a1f1dSLionel Sambuc namespace have_nondependent_base {
376*0a6a1f1dSLionel Sambuc template <typename T>
377*0a6a1f1dSLionel Sambuc struct A {
378*0a6a1f1dSLionel Sambuc // Nothing, lookup should fail.
379*0a6a1f1dSLionel Sambuc };
380*0a6a1f1dSLionel Sambuc template <typename T>
381*0a6a1f1dSLionel Sambuc struct B : A<T> { NameFromBase m; }; // expected-error {{unknown type name 'NameFromBase'}}
382*0a6a1f1dSLionel Sambuc struct C : A<int> { NameFromBase m; }; // expected-error {{unknown type name 'NameFromBase'}}
383*0a6a1f1dSLionel Sambuc }
384*0a6a1f1dSLionel Sambuc
385*0a6a1f1dSLionel Sambuc namespace type_in_base_of_dependent_base {
386*0a6a1f1dSLionel Sambuc struct A { typedef int NameFromBase; };
387*0a6a1f1dSLionel Sambuc template <typename T>
388*0a6a1f1dSLionel Sambuc struct B : A {};
389*0a6a1f1dSLionel Sambuc // FIXME: MSVC accepts this.
390*0a6a1f1dSLionel Sambuc template <typename T>
391*0a6a1f1dSLionel Sambuc struct C : B<T> { NameFromBase m; }; // expected-error {{unknown type name 'NameFromBase'}}
392*0a6a1f1dSLionel Sambuc }
393*0a6a1f1dSLionel Sambuc
394*0a6a1f1dSLionel Sambuc namespace lookup_in_function_contexts {
395*0a6a1f1dSLionel Sambuc template <typename T> struct A { typedef T NameFromBase; };
396*0a6a1f1dSLionel Sambuc template <typename T>
397*0a6a1f1dSLionel Sambuc struct B : A<T> {
398*0a6a1f1dSLionel Sambuc // expected-warning@+1 {{lookup into dependent bases}}
lateSpecifiedFunclookup_in_function_contexts::B399*0a6a1f1dSLionel Sambuc static auto lateSpecifiedFunc() -> decltype(NameFromBase()) {
400*0a6a1f1dSLionel Sambuc return {};
401*0a6a1f1dSLionel Sambuc }
402*0a6a1f1dSLionel Sambuc
memberFunclookup_in_function_contexts::B403*0a6a1f1dSLionel Sambuc static void memberFunc() {
404*0a6a1f1dSLionel Sambuc NameFromBase x; // expected-warning {{lookup into dependent bases}}
405*0a6a1f1dSLionel Sambuc }
406*0a6a1f1dSLionel Sambuc
funcLocalClasslookup_in_function_contexts::B407*0a6a1f1dSLionel Sambuc static void funcLocalClass() {
408*0a6a1f1dSLionel Sambuc struct X {
409*0a6a1f1dSLionel Sambuc NameFromBase x; // expected-warning {{lookup into dependent bases}}
410*0a6a1f1dSLionel Sambuc } y;
411*0a6a1f1dSLionel Sambuc }
412*0a6a1f1dSLionel Sambuc
localClassMethodlookup_in_function_contexts::B413*0a6a1f1dSLionel Sambuc void localClassMethod() {
414*0a6a1f1dSLionel Sambuc struct X {
415*0a6a1f1dSLionel Sambuc void bar() {
416*0a6a1f1dSLionel Sambuc NameFromBase m; // expected-warning {{lookup into dependent bases}}
417*0a6a1f1dSLionel Sambuc }
418*0a6a1f1dSLionel Sambuc } x;
419*0a6a1f1dSLionel Sambuc x.bar();
420*0a6a1f1dSLionel Sambuc }
421*0a6a1f1dSLionel Sambuc
funcLambdalookup_in_function_contexts::B422*0a6a1f1dSLionel Sambuc static void funcLambda() {
423*0a6a1f1dSLionel Sambuc auto l = []() {
424*0a6a1f1dSLionel Sambuc NameFromBase x; // expected-warning {{lookup into dependent bases}}
425*0a6a1f1dSLionel Sambuc };
426*0a6a1f1dSLionel Sambuc l();
427*0a6a1f1dSLionel Sambuc }
428*0a6a1f1dSLionel Sambuc
constexprFunclookup_in_function_contexts::B429*0a6a1f1dSLionel Sambuc static constexpr int constexprFunc() {
430*0a6a1f1dSLionel Sambuc NameFromBase x = {}; // expected-warning {{lookup into dependent bases}}
431*0a6a1f1dSLionel Sambuc return sizeof(x);
432*0a6a1f1dSLionel Sambuc }
433*0a6a1f1dSLionel Sambuc
autoFunclookup_in_function_contexts::B434*0a6a1f1dSLionel Sambuc static auto autoFunc() {
435*0a6a1f1dSLionel Sambuc NameFromBase x; // expected-warning {{lookup into dependent bases}}
436*0a6a1f1dSLionel Sambuc return x;
437*0a6a1f1dSLionel Sambuc }
438*0a6a1f1dSLionel Sambuc };
439*0a6a1f1dSLionel Sambuc
440*0a6a1f1dSLionel Sambuc // Force us to parse the methods.
441*0a6a1f1dSLionel Sambuc template struct B<int>;
442*0a6a1f1dSLionel Sambuc }
443*0a6a1f1dSLionel Sambuc
444*0a6a1f1dSLionel Sambuc namespace function_template_deduction {
445*0a6a1f1dSLionel Sambuc // Overloaded function templates.
f()446*0a6a1f1dSLionel Sambuc template <int N> int f() { return N; }
f()447*0a6a1f1dSLionel Sambuc template <typename T> int f() { return sizeof(T); }
448*0a6a1f1dSLionel Sambuc
449*0a6a1f1dSLionel Sambuc // Dependent base class with type.
450*0a6a1f1dSLionel Sambuc template <typename T>
451*0a6a1f1dSLionel Sambuc struct A { typedef T NameFromBase; };
452*0a6a1f1dSLionel Sambuc template <typename T>
453*0a6a1f1dSLionel Sambuc struct B : A<T> {
454*0a6a1f1dSLionel Sambuc // expected-warning@+1 {{found via unqualified lookup into dependent bases}}
455*0a6a1f1dSLionel Sambuc int x = f<NameFromBase>();
456*0a6a1f1dSLionel Sambuc };
457*0a6a1f1dSLionel Sambuc
458*0a6a1f1dSLionel Sambuc // Dependent base class with enum.
459*0a6a1f1dSLionel Sambuc template <typename T> struct C { enum { NameFromBase = 4 }; };
460*0a6a1f1dSLionel Sambuc template <typename T> struct D : C<T> {
461*0a6a1f1dSLionel Sambuc // expected-warning@+1 {{use of undeclared identifier 'NameFromBase'; unqualified lookup into dependent bases}}
462*0a6a1f1dSLionel Sambuc int x = f<NameFromBase>();
463*0a6a1f1dSLionel Sambuc };
464*0a6a1f1dSLionel Sambuc }
465*0a6a1f1dSLionel Sambuc
466*0a6a1f1dSLionel Sambuc namespace function_template_undef_impl {
467*0a6a1f1dSLionel Sambuc template<class T>
f()468*0a6a1f1dSLionel Sambuc void f() {
469*0a6a1f1dSLionel Sambuc Undef::staticMethod(); // expected-error {{use of undeclared identifier 'Undef'}}
470*0a6a1f1dSLionel Sambuc UndefVar.method(); // expected-error {{use of undeclared identifier 'UndefVar'}}
471*0a6a1f1dSLionel Sambuc }
472*0a6a1f1dSLionel Sambuc }
473*0a6a1f1dSLionel Sambuc
474*0a6a1f1dSLionel Sambuc namespace PR20716 {
475*0a6a1f1dSLionel Sambuc template <template <typename T> class A>
476*0a6a1f1dSLionel Sambuc struct B : A<int>
477*0a6a1f1dSLionel Sambuc {
478*0a6a1f1dSLionel Sambuc XXX x; // expected-error {{unknown type name}}
479*0a6a1f1dSLionel Sambuc };
480*0a6a1f1dSLionel Sambuc
481*0a6a1f1dSLionel Sambuc template <typename T>
482*0a6a1f1dSLionel Sambuc struct C {};
483*0a6a1f1dSLionel Sambuc
484*0a6a1f1dSLionel Sambuc template <typename T>
485*0a6a1f1dSLionel Sambuc using D = C<T>;
486*0a6a1f1dSLionel Sambuc
487*0a6a1f1dSLionel Sambuc template <typename T>
488*0a6a1f1dSLionel Sambuc struct E : D<T>
489*0a6a1f1dSLionel Sambuc {
490*0a6a1f1dSLionel Sambuc XXX x; // expected-error {{unknown type name}}
491*0a6a1f1dSLionel Sambuc };
492*0a6a1f1dSLionel Sambuc }
493