1 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++1y -fms-compatibility -fno-spell-checking -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++20 -fms-compatibility -fno-spell-checking -fsyntax-only -verify %s
8 void f(T a
) { }// expected-note 2{{must qualify identifier to find this declaration in dependent base class}}
9 void g();// expected-note 2{{must qualify identifier to find this declaration in dependent base class}}
13 class B
: public A
<T
> {
17 f(a
); // expected-warning 2{{use of member 'f' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
18 g(); // expected-warning 2{{use of member 'g' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
22 template class B
<int>; // expected-note {{requested here}}
23 template class B
<char>; // expected-note {{requested here}}
32 template<class T
> void f(T
) {
33 XX
; //expected-error {{use of undeclared identifier 'XX'}}
34 A2::XX
; //expected-error {{no member named 'XX' in 'A2'}}
37 template void A2::f(int);
41 template<class T1
> void f(T1
) {
42 XX
; //expected-error {{use of undeclared identifier 'XX'}}
45 template void A3
<int>::f(int);
50 XX
; //expected-error {{use of undeclared identifier 'XX'}}
53 template class A4
<int>;
56 namespace lookup_dependent_bases_id_expr
{
58 template<class T
> class A
{
65 class B
: public A
<T
> {
68 var
= 3; // expected-warning {{use of undeclared identifier 'var'; unqualified lookup into dependent bases of class template 'B' is a Microsoft extension}}
72 template class B
<int>;
74 template<typename T
> struct C
;
76 // Test lookup with incomplete lookup context
78 auto C
<T
>::f() -> decltype(x
) { } // expected-error {{use of undeclared identifier 'x'}}
79 // expected-error@-1 {{out-of-line definition of 'f' from class 'C<T>' without definition}}
85 namespace lookup_dependent_base_class_static_function
{
90 static void static_func();// expected-note {{must qualify identifier to find this declaration in dependent base class}}
91 void func();// expected-note {{must qualify identifier to find this declaration in dependent base class}}
96 class B
: public A
<T
> {
99 static_func(); // expected-warning {{use of member 'static_func' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
100 func(); // expected-warning {{use of member '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}}
103 template class B
<int>; // expected-note {{requested here}}
109 namespace lookup_dependent_base_class_default_argument
{
114 static int f1(); // expected-note {{must qualify identifier to find this declaration in dependent base class}}
115 int f2(); // expected-note {{must qualify identifier to find this declaration in dependent base class}}
119 class B
: public A
<T
> {
121 void g1(int p
= f1());// expected-warning {{use of member 'f1' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
122 void g2(int p
= f2());// expected-warning {{use of member '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}}
128 b
.g1(); // expected-note {{required here}}
129 b
.g2(); // expected-note {{required here}}
135 namespace lookup_dependent_base_class_friend
{
140 static void g(); // expected-note {{must qualify identifier to find this declaration in dependent base class}}
144 class A
: public B
<T
> {
146 friend void foo(A
<T
> p
){
147 g(); // expected-warning {{use of member 'g' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
154 foo(a
); // expected-note {{requested here}}
160 namespace lookup_dependent_base_no_typo_correction
{
171 m_hWnd
= 1; // expected-warning {{use of undeclared identifier 'm_hWnd'; unqualified lookup into dependent bases of class template 'A' is a Microsoft extension}}
187 bool base_fun(void* p
) { return false; } // expected-note {{must qualify identifier to find this declaration in dependent base class}}
188 operator T
*() const { return 0; }
192 class Container
: public Base
<T
> {
194 template <typename S
>
195 bool operator=(const Container
<S
>& rhs
) {
196 return base_fun(rhs
); // expected-warning {{use of member 'base_fun' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
201 Container
<A
> text_provider
;
202 Container
<B
> text_provider2
;
203 text_provider2
= text_provider
; // expected-note {{in instantiation of function template specialization}}
206 } // namespace PR12701
214 template <typename T
> struct B
: T
{
215 int foo() { return a
; } // expected-warning {{lookup into dependent bases}}
216 int *bar() { return &a
; } // expected-warning {{lookup into dependent bases}}
217 int baz() { return T::a
; }
218 int T::*qux() { return &T::a
; }
219 static int T::*stuff() { return &T::a
; }
220 static int stuff1() { return T::sa
; }
221 static int *stuff2() { return &T::sa
; }
222 static int stuff3() { return sa
; } // expected-warning {{lookup into dependent bases}}
223 static int *stuff4() { return &sa
; } // expected-warning {{lookup into dependent bases}}
226 template <typename T
> struct C
: T
{
227 int foo() { return b
; } // expected-error {{no member named 'b' in 'PR16014::C<A>'}} expected-warning {{lookup into dependent bases}}
228 int *bar() { return &b
; } // expected-error {{no member named 'b' in 'PR16014::C<A>'}} expected-warning {{lookup into dependent bases}}
229 int baz() { return T::b
; } // expected-error {{no member named 'b' in 'PR16014::A'}}
230 int T::*qux() { return &T::b
; } // expected-error {{no member named 'b' in 'PR16014::A'}}
231 int T::*fuz() { return &U::a
; } // expected-error {{no member named 'U' in 'PR16014::C<A>'}} \
232 // expected-warning {{unqualified lookup into dependent bases of class template 'C'}}
235 template struct B
<A
>;
236 template struct C
<A
>; // expected-note-re 1+ {{in instantiation of member function 'PR16014::C<PR16014::A>::{{.*}}' requested here}}
238 template <typename T
> struct D
: T
{
241 // FIXME: MSVC can find this in D's base T! Even worse, if ::sa exists,
242 // clang will use it instead.
243 return sa
; // expected-error {{use of undeclared identifier 'sa'}}
247 template struct D
<A
>;
255 ::undef(); // expected-error {{no member named 'undef' in the global namespace}}
258 ::UndefClass::undef(); // expected-error {{no member named 'UndefClass' in the global namespace}}
261 B::qux(); // expected-error {{no member named 'B' in 'PR19233::A<D>'}} \
262 // expected-warning {{unqualified lookup into dependent bases of class template 'A'}}
266 struct B
{ void qux(); };
268 template struct A
<C
>; // No error! B is a base of A<C>, and qux is available.
271 template struct A
<D
>; // expected-note {{in instantiation of member function 'PR19233::A<PR19233::D>::baz' requested here}}
275 namespace nonmethod_missing_this
{
276 template <typename T
> struct Base
{ int y
= 42; };
277 template <typename T
> struct Derived
: Base
<T
> {
278 int x
= y
; // expected-warning {{lookup into dependent bases}}
279 auto foo(int j
) -> decltype(y
* j
) { // expected-warning {{lookup into dependent bases}}
280 return y
* j
; // expected-warning {{lookup into dependent bases}}
283 return [&] { return y
; }(); // expected-warning {{lookup into dependent bases}}
286 template struct Derived
<int>;
289 namespace typedef_in_base
{
290 template <typename T
> struct A
{ typedef T 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>) == 4, "");
297 namespace struct_in_base
{
298 template <typename T
> struct A
{ struct NameFromBase
{}; };
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>) == 1, "");
305 namespace enum_in_base
{
306 template <typename T
> struct A
{ enum NameFromBase
{ X
}; };
307 template <typename T
> struct B
: A
<T
> {
308 NameFromBase m
; // expected-warning {{found via unqualified lookup into dependent bases}}
310 static_assert(sizeof(B
<int>) == sizeof(A
<int>::NameFromBase
), "");
313 namespace two_types_in_base
{
314 template <typename T
> struct A
{ typedef T NameFromBase
; }; // expected-note {{member type 'int' found by ambiguous name lookup}}
315 template <typename T
> struct B
{ struct NameFromBase
{ T m
; }; }; // expected-note {{member type 'two_types_in_base::B<int>::NameFromBase' found by ambiguous name lookup}}
316 template <typename T
> struct C
: A
<T
>, B
<T
> {
317 NameFromBase m
; // expected-error {{member 'NameFromBase' found in multiple base classes of different types}} expected-warning {{use of member 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
319 static_assert(sizeof(C
<int>) != 0, ""); // expected-note {{in instantiation of template class 'two_types_in_base::C<int>' requested here}}
322 namespace type_and_decl_in_base
{
323 template <typename T
> struct A
{ typedef T NameFromBase
; };
324 template <typename T
> struct B
{ static const T NameFromBase
= 42; };
325 template <typename T
> struct C
: A
<T
>, B
<T
> {
326 NameFromBase m
; // expected-error {{unknown type name 'NameFromBase'}}
330 namespace classify_type_from_base
{
331 template <typename T
> struct A
{ struct NameFromBase
{}; };
332 template <typename T
> struct B
: A
<T
> {
333 A
<NameFromBase
> m
; // expected-warning {{found via unqualified lookup into dependent bases}}
337 namespace classify_nontype_from_base
{
338 // MSVC does not do lookup of non-type declarations from dependent template base
339 // classes. The extra lookup only applies to types.
340 template <typename T
> struct A
{ void NameFromBase() {} };
341 template <void (*F
)()> struct B
{ };
342 template <typename T
> struct C
: A
<T
> {
343 B
<C::NameFromBase
> a
; // correct
344 B
<NameFromBase
> b
; // expected-error {{use of undeclared identifier 'NameFromBase'}}
348 namespace template_in_base
{
349 template <typename T
> struct A
{
350 template <typename U
> struct NameFromBase
{ U x
; };
352 template <typename T
> struct B
: A
<T
> {
354 typename
B::template NameFromBase
<T
> m
;
356 template <typename T
> struct C
: A
<T
> {
358 NameFromBase
<T
> m
; // expected-error {{no template named 'NameFromBase'}}
362 namespace type_in_inner_class_in_base
{
363 template <typename T
>
365 struct B
{ typedef T NameFromBase
; };
367 template <typename T
>
368 struct C
: A
<T
>::B
{ NameFromBase m
; }; // expected-error {{unknown type name 'NameFromBase'}}
371 namespace type_in_inner_template_class_in_base
{
372 template <typename T
>
374 template <typename U
> struct B
{ typedef U InnerType
; };
376 template <typename T
>
377 struct C
: A
<T
>::template B
<T
> {
378 NameFromBase m
; // expected-error {{unknown type name 'NameFromBase'}}
382 namespace have_nondependent_base
{
383 template <typename T
>
385 // Nothing, lookup should fail.
387 template <typename T
>
388 struct B
: A
<T
> { NameFromBase m
; }; // expected-error {{unknown type name 'NameFromBase'}}
389 struct C
: A
<int> { NameFromBase m
; }; // expected-error {{unknown type name 'NameFromBase'}}
392 namespace type_in_base_of_dependent_base
{
393 struct A
{ typedef int NameFromBase
; };
394 template <typename T
>
396 template <typename T
>
397 struct C
: B
<T
> { NameFromBase m
; }; // expected-warning {{use of member 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
400 namespace type_in_second_dependent_base
{
401 template <typename T
>
404 struct B
{ typedef T NameFromBase
; };
405 template <typename T
>
406 struct D
: A
<T
>, B
<T
> { NameFromBase m
; }; // expected-warning {{use of member 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
409 namespace type_in_second_non_dependent_base
{
411 struct B
{ typedef int NameFromBase
; };
414 template <typename T
>
415 struct D
: C
<T
> { NameFromBase m
; }; // expected-warning {{use of member 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
418 namespace type_in_virtual_base_of_dependent_base
{
419 template <typename T
>
420 struct A
{ typedef T NameFromBase
; };
421 template <typename T
>
422 struct B
: virtual A
<T
> {};
423 template <typename T
>
424 struct C
: B
<T
>, virtual A
<T
> { NameFromBase m
; }; // expected-warning {{use of member 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
428 namespace type_in_base_of_multiple_dependent_bases
{
429 template <typename T
>
430 struct A
{ typedef T NameFromBase
; };
431 template <typename T
>
432 struct B
: public A
<T
> {};
433 template <typename T
>
434 struct C
: B
<T
>, public A
<T
> { NameFromBase m
; }; // expected-warning {{use of member '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:}}
435 C
<int> c
; // expected-note {{in instantiation of template class 'type_in_base_of_multiple_dependent_bases::C<int>' requested here}}
438 namespace type_in_dependent_base_of_non_dependent_type
{
439 template<typename T
> struct A
{ typedef int NameFromBase
; };
440 template<typename T
> struct B
: A
<T
> {
442 template<typename TT
>
444 NameFromBase m
; // expected-warning {{use of member 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
447 NameFromBase m
; // expected-warning {{use of member 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
450 template<typename T
> struct B
<T
>::C
: B
{
451 NameFromBase m
; // expected-warning {{use of member 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
453 template<typename T
> struct F
: B
<T
>::C
{
454 NameFromBase m
; // expected-error {{unknown type name 'NameFromBase'}}
458 namespace lookup_in_function_contexts
{
459 template <typename T
> struct A
{ typedef T NameFromBase
; };
460 template <typename T
>
462 // expected-warning@+1 {{lookup into dependent bases}}
463 static auto lateSpecifiedFunc() -> decltype(NameFromBase()) {
467 static void memberFunc() {
468 NameFromBase x
; // expected-warning {{lookup into dependent bases}}
471 static void funcLocalClass() {
473 NameFromBase x
; // expected-warning {{lookup into dependent bases}}
477 void localClassMethod() {
480 NameFromBase m
; // expected-warning {{lookup into dependent bases}}
486 static void funcLambda() {
488 NameFromBase x
; // expected-warning {{lookup into dependent bases}}
493 static constexpr int constexprFunc() {
494 NameFromBase x
= {}; // expected-warning {{lookup into dependent bases}}
498 static auto autoFunc() {
499 NameFromBase x
; // expected-warning {{lookup into dependent bases}}
504 // Force us to parse the methods.
505 template struct B
<int>;
508 namespace function_template_deduction
{
509 // Overloaded function templates.
510 template <int N
> int f() { return N
; }
511 template <typename T
> int f() { return sizeof(T
); }
513 // Dependent base class with type.
514 template <typename T
>
515 struct A
{ typedef T NameFromBase
; };
516 template <typename T
>
518 // expected-warning@+1 {{found via unqualified lookup into dependent bases}}
519 int x
= f
<NameFromBase
>();
522 // Dependent base class with enum.
523 template <typename T
> struct C
{ enum { NameFromBase
= 4 }; };
524 template <typename T
> struct D
: C
<T
> {
525 // expected-warning@+1 {{use of undeclared identifier 'NameFromBase'; unqualified lookup into dependent bases}}
526 int x
= f
<NameFromBase
>();
530 namespace function_template_undef_impl
{
533 Undef::staticMethod(); // expected-error {{use of undeclared identifier 'Undef'}}
534 UndefVar
.method(); // expected-error {{use of undeclared identifier 'UndefVar'}}
539 template <template <typename T
> class A
>
542 XXX x
; // expected-error {{unknown type name}}
545 template <typename T
>
548 template <typename T
>
551 template <typename T
>
554 XXX x
; // expected-error {{unknown type name}}
561 void f(); // expected-note{{must qualify identifier to find this declaration in dependent base class}}
563 template <typename T
> struct Template
: T
{
565 f(); // expected-warning {{found via unqualified lookup into dependent bases}}
570 x
.member(); // expected-note{{requested here}}
575 // Don't delay lookup in SFINAE context.
576 template <typename T
> decltype(g(T())) check(); // expected-note{{candidate template ignored: substitution failure [with T = int]: use of undeclared identifier 'g'}}
577 decltype(check
<int>()) x
; // expected-error{{no matching function for call to 'check'}}
580 template <typename T
> decltype(h(T())) check2(); // expected-note{{candidate template ignored: substitution failure [with T = int]: no matching function for call to 'h'}}
581 decltype(check2
<int>()) y
; // expected-error{{no matching function for call to 'check2'}}
584 // We also allow unqualified lookup into bases in contexts where the we know the
585 // undeclared identifier *must* be a type, such as a new expression or catch
587 template <typename T
>
588 struct UseUnqualifiedTypeNames
: T
{
590 void *P
= new TheType
; // expected-warning {{unqualified lookup}} expected-error {{no type}}
591 size_t x
= __builtin_offsetof(TheType
, f2
); // expected-warning {{unqualified lookup}} expected-error {{no type}}
593 } catch (TheType
) { // expected-warning {{unqualified lookup}} expected-error {{no type}}
595 enum E
: IntegerType
{ E0
= 42 }; // expected-warning {{unqualified lookup}} expected-error {{no type}}
596 _Atomic(TheType
) a
; // expected-warning {{unqualified lookup}} expected-error {{no type}}
600 template <typename T
>
601 void UseUnqualifiedTypeNames
<T
>::out_of_line() {
602 void *p
= new TheType
; // expected-warning {{unqualified lookup}} expected-error {{no type}}
605 typedef int IntegerType
;
610 template struct UseUnqualifiedTypeNames
<Base
>;
612 template struct UseUnqualifiedTypeNames
<BadBase
>; // expected-note-re 2 {{in instantiation {{.*}} requested here}}
614 namespace partial_template_lookup
{
619 template <class T
, class X
= Bar
>
624 typedef int BaseTypedef
;
627 // Partial template spec (unused)
629 class FooTemplated
<T
, Spare
> {};
631 // Partial template spec (used)
633 class FooTemplated
<T
, Bar
> : public FooBase
{};
635 // Full template spec
636 template <class T
, class X
>
637 class FooTemplated
: public FooTemplated
<T
, Bar
> {
639 BaseTypedef Member
; // expected-warning {{unqualified lookup}}