1 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++1y -fms-compatibility -fno-spell-checking -fsyntax-only -verify %s
7 void f(T a
) { }// expected-note 2{{must qualify identifier to find this declaration in dependent base class}}
8 void g();// expected-note 2{{must qualify identifier to find this declaration in dependent base class}}
12 class B
: public A
<T
> {
16 f(a
); // expected-warning 2{{use of identifier 'f' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
17 g(); // expected-warning 2{{use of identifier 'g' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
21 template class B
<int>; // expected-note {{requested here}}
22 template class B
<char>; // expected-note {{requested here}}
31 template<class T
> void f(T
) {
32 XX
; //expected-error {{use of undeclared identifier 'XX'}}
33 A2::XX
; //expected-error {{no member named 'XX' in 'A2'}}
36 template void A2::f(int);
40 template<class T1
> void f(T1
) {
41 XX
; //expected-error {{use of undeclared identifier 'XX'}}
44 template void A3
<int>::f(int);
49 XX
; //expected-error {{use of undeclared identifier 'XX'}}
52 template class A4
<int>;
55 namespace lookup_dependent_bases_id_expr
{
57 template<class T
> class A
{
64 class B
: public A
<T
> {
67 var
= 3; // expected-warning {{use of undeclared identifier 'var'; unqualified lookup into dependent bases of class template 'B' is a Microsoft extension}}
71 template class B
<int>;
77 namespace lookup_dependent_base_class_static_function
{
82 static void static_func();// expected-note {{must qualify identifier to find this declaration in dependent base class}}
83 void func();// expected-note {{must qualify identifier to find this declaration in dependent base class}}
88 class B
: public A
<T
> {
91 static_func(); // expected-warning {{use of identifier 'static_func' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
92 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}}
95 template class B
<int>; // expected-note {{requested here}}
101 namespace lookup_dependent_base_class_default_argument
{
106 static int f1(); // expected-note {{must qualify identifier to find this declaration in dependent base class}}
107 int f2(); // expected-note {{must qualify identifier to find this declaration in dependent base class}}
111 class B
: public A
<T
> {
113 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}}
114 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}}
120 b
.g1(); // expected-note {{required here}}
121 b
.g2(); // expected-note {{required here}}
127 namespace lookup_dependent_base_class_friend
{
132 static void g(); // expected-note {{must qualify identifier to find this declaration in dependent base class}}
136 class A
: public B
<T
> {
138 friend void foo(A
<T
> p
){
139 g(); // expected-warning {{use of identifier 'g' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
146 foo(a
); // expected-note {{requested here}}
152 namespace lookup_dependent_base_no_typo_correction
{
163 m_hWnd
= 1; // expected-warning {{use of undeclared identifier 'm_hWnd'; unqualified lookup into dependent bases of class template 'A' is a Microsoft extension}}
179 bool base_fun(void* p
) { return false; } // expected-note {{must qualify identifier to find this declaration in dependent base class}}
180 operator T
*() const { return 0; }
184 class Container
: public Base
<T
> {
186 template <typename S
>
187 bool operator=(const Container
<S
>& rhs
) {
188 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}}
193 Container
<A
> text_provider
;
194 Container
<B
> text_provider2
;
195 text_provider2
= text_provider
; // expected-note {{in instantiation of function template specialization}}
198 } // namespace PR12701
206 template <typename T
> struct B
: T
{
207 int foo() { return a
; } // expected-warning {{lookup into dependent bases}}
208 int *bar() { return &a
; } // expected-warning {{lookup into dependent bases}}
209 int baz() { return T::a
; }
210 int T::*qux() { return &T::a
; }
211 static int T::*stuff() { return &T::a
; }
212 static int stuff1() { return T::sa
; }
213 static int *stuff2() { return &T::sa
; }
214 static int stuff3() { return sa
; } // expected-warning {{lookup into dependent bases}}
215 static int *stuff4() { return &sa
; } // expected-warning {{lookup into dependent bases}}
218 template <typename T
> struct C
: T
{
219 int foo() { return b
; } // expected-error {{no member named 'b' in 'PR16014::C<PR16014::A>'}} expected-warning {{lookup into dependent bases}}
220 int *bar() { return &b
; } // expected-error {{no member named 'b' in 'PR16014::C<PR16014::A>'}} expected-warning {{lookup into dependent bases}}
221 int baz() { return T::b
; } // expected-error {{no member named 'b' in 'PR16014::A'}}
222 int T::*qux() { return &T::b
; } // expected-error {{no member named 'b' in 'PR16014::A'}}
223 int T::*fuz() { return &U::a
; } // expected-error {{use of undeclared identifier 'U'}} \
224 // expected-warning {{unqualified lookup into dependent bases of class template 'C'}}
227 template struct B
<A
>;
228 template struct C
<A
>; // expected-note-re 1+ {{in instantiation of member function 'PR16014::C<PR16014::A>::{{.*}}' requested here}}
230 template <typename T
> struct D
: T
{
233 // FIXME: MSVC can find this in D's base T! Even worse, if ::sa exists,
234 // clang will use it instead.
235 return sa
; // expected-error {{use of undeclared identifier 'sa'}}
239 template struct D
<A
>;
247 ::undef(); // expected-error {{no member named 'undef' in the global namespace}}
250 ::UndefClass::undef(); // expected-error {{no member named 'UndefClass' in the global namespace}}
253 B::qux(); // expected-error {{use of undeclared identifier 'B'}} \
254 // expected-warning {{unqualified lookup into dependent bases of class template 'A'}}
258 struct B
{ void qux(); };
260 template struct A
<C
>; // No error! B is a base of A<C>, and qux is available.
263 template struct A
<D
>; // expected-note {{in instantiation of member function 'PR19233::A<PR19233::D>::baz' requested here}}
267 namespace nonmethod_missing_this
{
268 template <typename T
> struct Base
{ int y
= 42; };
269 template <typename T
> struct Derived
: Base
<T
> {
270 int x
= y
; // expected-warning {{lookup into dependent bases}}
271 auto foo(int j
) -> decltype(y
* j
) { // expected-warning {{lookup into dependent bases}}
272 return y
* j
; // expected-warning {{lookup into dependent bases}}
275 return [&] { return y
; }(); // expected-warning {{lookup into dependent bases}}
278 template struct Derived
<int>;
281 namespace typedef_in_base
{
282 template <typename T
> struct A
{ typedef T NameFromBase
; };
283 template <typename T
> struct B
: A
<T
> {
284 NameFromBase m
; // expected-warning {{found via unqualified lookup into dependent bases}}
286 static_assert(sizeof(B
<int>) == 4, "");
289 namespace struct_in_base
{
290 template <typename T
> struct A
{ struct NameFromBase
{}; };
291 template <typename T
> struct B
: A
<T
> {
292 NameFromBase m
; // expected-warning {{found via unqualified lookup into dependent bases}}
294 static_assert(sizeof(B
<int>) == 1, "");
297 namespace enum_in_base
{
298 template <typename T
> struct A
{ enum NameFromBase
{ X
}; };
299 template <typename T
> struct B
: A
<T
> {
300 NameFromBase m
; // expected-warning {{found via unqualified lookup into dependent bases}}
302 static_assert(sizeof(B
<int>) == sizeof(A
<int>::NameFromBase
), "");
305 namespace two_types_in_base
{
306 template <typename T
> struct A
{ typedef T NameFromBase
; }; // expected-note {{member found by ambiguous name lookup}}
307 template <typename T
> struct B
{ struct NameFromBase
{ T m
; }; }; // expected-note {{member found by ambiguous name lookup}}
308 template <typename T
> struct C
: A
<T
>, B
<T
> {
309 NameFromBase m
; // expected-error {{member 'NameFromBase' found in multiple base classes of different types}} expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
311 static_assert(sizeof(C
<int>) != 0, ""); // expected-note {{in instantiation of template class 'two_types_in_base::C<int>' requested here}}
314 namespace type_and_decl_in_base
{
315 template <typename T
> struct A
{ typedef T NameFromBase
; };
316 template <typename T
> struct B
{ static const T NameFromBase
= 42; };
317 template <typename T
> struct C
: A
<T
>, B
<T
> {
318 NameFromBase m
; // expected-error {{unknown type name 'NameFromBase'}}
322 namespace classify_type_from_base
{
323 template <typename T
> struct A
{ struct NameFromBase
{}; };
324 template <typename T
> struct B
: A
<T
> {
325 A
<NameFromBase
> m
; // expected-warning {{found via unqualified lookup into dependent bases}}
329 namespace classify_nontype_from_base
{
330 // MSVC does not do lookup of non-type declarations from dependent template base
331 // classes. The extra lookup only applies to types.
332 template <typename T
> struct A
{ void NameFromBase() {} };
333 template <void (*F
)()> struct B
{ };
334 template <typename T
> struct C
: A
<T
> {
335 B
<C::NameFromBase
> a
; // correct
336 B
<NameFromBase
> b
; // expected-error {{use of undeclared identifier 'NameFromBase'}}
340 namespace template_in_base
{
341 template <typename T
> struct A
{
342 template <typename U
> struct NameFromBase
{ U x
; };
344 template <typename T
> struct B
: A
<T
> {
346 typename
B::template NameFromBase
<T
> m
;
348 template <typename T
> struct C
: A
<T
> {
350 NameFromBase
<T
> m
; // expected-error {{no template named 'NameFromBase'}}
354 namespace type_in_inner_class_in_base
{
355 template <typename T
>
357 struct B
{ typedef T NameFromBase
; };
359 template <typename T
>
360 struct C
: A
<T
>::B
{ NameFromBase m
; }; // expected-error {{unknown type name 'NameFromBase'}}
363 namespace type_in_inner_template_class_in_base
{
364 template <typename T
>
366 template <typename U
> struct B
{ typedef U InnerType
; };
368 template <typename T
>
369 struct C
: A
<T
>::template B
<T
> {
370 NameFromBase m
; // expected-error {{unknown type name 'NameFromBase'}}
374 namespace have_nondependent_base
{
375 template <typename T
>
377 // Nothing, lookup should fail.
379 template <typename T
>
380 struct B
: A
<T
> { NameFromBase m
; }; // expected-error {{unknown type name 'NameFromBase'}}
381 struct C
: A
<int> { NameFromBase m
; }; // expected-error {{unknown type name 'NameFromBase'}}
384 namespace type_in_base_of_dependent_base
{
385 struct A
{ typedef int NameFromBase
; };
386 template <typename T
>
388 template <typename T
>
389 struct C
: B
<T
> { NameFromBase m
; }; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
392 namespace type_in_second_dependent_base
{
393 template <typename T
>
396 struct B
{ typedef T NameFromBase
; };
397 template <typename T
>
398 struct D
: A
<T
>, B
<T
> { NameFromBase m
; }; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
401 namespace type_in_second_non_dependent_base
{
403 struct B
{ typedef int NameFromBase
; };
406 template <typename T
>
407 struct D
: C
<T
> { NameFromBase m
; }; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
410 namespace type_in_virtual_base_of_dependent_base
{
411 template <typename T
>
412 struct A
{ typedef T NameFromBase
; };
413 template <typename T
>
414 struct B
: virtual A
<T
> {};
415 template <typename T
>
416 struct C
: B
<T
>, virtual A
<T
> { NameFromBase m
; }; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
420 namespace type_in_base_of_multiple_dependent_bases
{
421 template <typename T
>
422 struct A
{ typedef T NameFromBase
; };
423 template <typename T
>
424 struct B
: public A
<T
> {};
425 template <typename T
>
426 struct C
: B
<T
>, public A
<T
> { NameFromBase m
; }; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} expected-warning {{direct base 'A<int>' is inaccessible due to ambiguity:}}
427 C
<int> c
; // expected-note {{in instantiation of template class 'type_in_base_of_multiple_dependent_bases::C<int>' requested here}}
430 namespace type_in_dependent_base_of_non_dependent_type
{
431 template<typename T
> struct A
{ typedef int NameFromBase
; };
432 template<typename T
> struct B
: A
<T
> {
434 template<typename TT
>
436 NameFromBase m
; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
439 NameFromBase m
; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
442 template<typename T
> struct B
<T
>::C
: B
{
443 NameFromBase m
; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
445 template<typename T
> struct F
: B
<T
>::C
{
446 NameFromBase m
; // expected-error {{unknown type name 'NameFromBase'}}
450 namespace lookup_in_function_contexts
{
451 template <typename T
> struct A
{ typedef T NameFromBase
; };
452 template <typename T
>
454 // expected-warning@+1 {{lookup into dependent bases}}
455 static auto lateSpecifiedFunc() -> decltype(NameFromBase()) {
459 static void memberFunc() {
460 NameFromBase x
; // expected-warning {{lookup into dependent bases}}
463 static void funcLocalClass() {
465 NameFromBase x
; // expected-warning {{lookup into dependent bases}}
469 void localClassMethod() {
472 NameFromBase m
; // expected-warning {{lookup into dependent bases}}
478 static void funcLambda() {
480 NameFromBase x
; // expected-warning {{lookup into dependent bases}}
485 static constexpr int constexprFunc() {
486 NameFromBase x
= {}; // expected-warning {{lookup into dependent bases}}
490 static auto autoFunc() {
491 NameFromBase x
; // expected-warning {{lookup into dependent bases}}
496 // Force us to parse the methods.
497 template struct B
<int>;
500 namespace function_template_deduction
{
501 // Overloaded function templates.
502 template <int N
> int f() { return N
; }
503 template <typename T
> int f() { return sizeof(T
); }
505 // Dependent base class with type.
506 template <typename T
>
507 struct A
{ typedef T NameFromBase
; };
508 template <typename T
>
510 // expected-warning@+1 {{found via unqualified lookup into dependent bases}}
511 int x
= f
<NameFromBase
>();
514 // Dependent base class with enum.
515 template <typename T
> struct C
{ enum { NameFromBase
= 4 }; };
516 template <typename T
> struct D
: C
<T
> {
517 // expected-warning@+1 {{use of undeclared identifier 'NameFromBase'; unqualified lookup into dependent bases}}
518 int x
= f
<NameFromBase
>();
522 namespace function_template_undef_impl
{
525 Undef::staticMethod(); // expected-error {{use of undeclared identifier 'Undef'}}
526 UndefVar
.method(); // expected-error {{use of undeclared identifier 'UndefVar'}}
531 template <template <typename T
> class A
>
534 XXX x
; // expected-error {{unknown type name}}
537 template <typename T
>
540 template <typename T
>
543 template <typename T
>
546 XXX x
; // expected-error {{unknown type name}}
553 void f(); // expected-note{{must qualify identifier to find this declaration in dependent base class}}
555 template <typename T
> struct Template
: T
{
557 f(); // expected-warning {{found via unqualified lookup into dependent bases}}
562 x
.member(); // expected-note{{requested here}}
567 // Don't delay lookup in SFINAE context.
568 template <typename T
> decltype(g(T())) check(); // expected-note{{candidate template ignored: substitution failure [with T = int]: use of undeclared identifier 'g'}}
569 decltype(check
<int>()) x
; // expected-error{{no matching function for call to 'check'}}
572 template <typename T
> decltype(h(T())) check2(); // expected-note{{candidate template ignored: substitution failure [with T = int]: no matching function for call to 'h'}}
573 decltype(check2
<int>()) y
; // expected-error{{no matching function for call to 'check2'}}
576 // We also allow unqualified lookup into bases in contexts where the we know the
577 // undeclared identifier *must* be a type, such as a new expression or catch
579 template <typename T
>
580 struct UseUnqualifiedTypeNames
: T
{
582 void *P
= new TheType
; // expected-warning {{unqualified lookup}} expected-error {{no type}}
583 size_t x
= __builtin_offsetof(TheType
, f2
); // expected-warning {{unqualified lookup}} expected-error {{no type}}
585 } catch (TheType
) { // expected-warning {{unqualified lookup}} expected-error {{no type}}
587 enum E
: IntegerType
{ E0
= 42 }; // expected-warning {{unqualified lookup}} expected-error {{no type}}
588 _Atomic(TheType
) a
; // expected-warning {{unqualified lookup}} expected-error {{no type}}
592 template <typename T
>
593 void UseUnqualifiedTypeNames
<T
>::out_of_line() {
594 void *p
= new TheType
; // expected-warning {{unqualified lookup}} expected-error {{no type}}
597 typedef int IntegerType
;
602 template struct UseUnqualifiedTypeNames
<Base
>;
604 template struct UseUnqualifiedTypeNames
<BadBase
>; // expected-note-re 2 {{in instantiation {{.*}} requested here}}
606 namespace partial_template_lookup
{
611 template <class T
, class X
= Bar
>
616 typedef int BaseTypedef
;
619 // Partial template spec (unused)
621 class FooTemplated
<T
, Spare
> {};
623 // Partial template spec (used)
625 class FooTemplated
<T
, Bar
> : public FooBase
{};
627 // Full template spec
628 template <class T
, class X
>
629 class FooTemplated
: public FooTemplated
<T
, Bar
> {
631 BaseTypedef Member
; // expected-warning {{unqualified lookup}}