// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++1y -fms-compatibility -fno-spell-checking -fsyntax-only -verify %s template class A { public: void f(T a) { }// expected-note 2{{must qualify identifier to find this declaration in dependent base class}} void g();// expected-note 2{{must qualify identifier to find this declaration in dependent base class}} }; template class B : public A { public: void z(T a) { f(a); // expected-warning 2{{use of identifier 'f' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} g(); // expected-warning 2{{use of identifier 'g' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} } }; template class B; // expected-note {{requested here}} template class B; // expected-note {{requested here}} void test() { B b; b.z(3); } struct A2 { template void f(T) { XX; //expected-error {{use of undeclared identifier 'XX'}} A2::XX; //expected-error {{no member named 'XX' in 'A2'}} } }; template void A2::f(int); template struct A3 { template void f(T1) { XX; //expected-error {{use of undeclared identifier 'XX'}} } }; template void A3::f(int); template struct A4 { void f(char) { XX; //expected-error {{use of undeclared identifier 'XX'}} } }; template class A4; namespace lookup_dependent_bases_id_expr { template class A { public: int var; }; template class B : public A { public: void f() { var = 3; // expected-warning {{use of undeclared identifier 'var'; unqualified lookup into dependent bases of class template 'B' is a Microsoft extension}} } }; template class B; } namespace lookup_dependent_base_class_static_function { template class A { public: static void static_func();// expected-note {{must qualify identifier to find this declaration in dependent base class}} void func();// expected-note {{must qualify identifier to find this declaration in dependent base class}} }; template class B : public A { public: static void z2(){ static_func(); // expected-warning {{use of identifier 'static_func' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} 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}} } }; template class B; // expected-note {{requested here}} } namespace lookup_dependent_base_class_default_argument { template class A { public: static int f1(); // expected-note {{must qualify identifier to find this declaration in dependent base class}} int f2(); // expected-note {{must qualify identifier to find this declaration in dependent base class}} }; template class B : public A { public: 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}} 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}} }; void foo() { B b; b.g1(); // expected-note {{required here}} b.g2(); // expected-note {{required here}} } } namespace lookup_dependent_base_class_friend { template class B { public: static void g(); // expected-note {{must qualify identifier to find this declaration in dependent base class}} }; template class A : public B { public: friend void foo(A p){ g(); // expected-warning {{use of identifier 'g' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} } }; int main2() { A a; foo(a); // expected-note {{requested here}} } } namespace lookup_dependent_base_no_typo_correction { class C { public: int m_hWnd; }; template class A : public T { public: void f(int hWnd) { m_hWnd = 1; // expected-warning {{use of undeclared identifier 'm_hWnd'; unqualified lookup into dependent bases of class template 'A' is a Microsoft extension}} } }; template class A; } namespace PR12701 { class A {}; class B {}; template class Base { public: bool base_fun(void* p) { return false; } // expected-note {{must qualify identifier to find this declaration in dependent base class}} operator T*() const { return 0; } }; template class Container : public Base { public: template bool operator=(const Container& rhs) { 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}} } }; void f() { Container text_provider; Container text_provider2; text_provider2 = text_provider; // expected-note {{in instantiation of function template specialization}} } } // namespace PR12701 namespace PR16014 { struct A { int a; static int sa; }; template struct B : T { int foo() { return a; } // expected-warning {{lookup into dependent bases}} int *bar() { return &a; } // expected-warning {{lookup into dependent bases}} int baz() { return T::a; } int T::*qux() { return &T::a; } static int T::*stuff() { return &T::a; } static int stuff1() { return T::sa; } static int *stuff2() { return &T::sa; } static int stuff3() { return sa; } // expected-warning {{lookup into dependent bases}} static int *stuff4() { return &sa; } // expected-warning {{lookup into dependent bases}} }; template struct C : T { int foo() { return b; } // expected-error {{no member named 'b' in 'PR16014::C'}} expected-warning {{lookup into dependent bases}} int *bar() { return &b; } // expected-error {{no member named 'b' in 'PR16014::C'}} expected-warning {{lookup into dependent bases}} int baz() { return T::b; } // expected-error {{no member named 'b' in 'PR16014::A'}} int T::*qux() { return &T::b; } // expected-error {{no member named 'b' in 'PR16014::A'}} int T::*fuz() { return &U::a; } // expected-error {{use of undeclared identifier 'U'}} \ // expected-warning {{unqualified lookup into dependent bases of class template 'C'}} }; template struct B; template struct C; // expected-note-re 1+ {{in instantiation of member function 'PR16014::C::{{.*}}' requested here}} template struct D : T { struct Inner { int foo() { // FIXME: MSVC can find this in D's base T! Even worse, if ::sa exists, // clang will use it instead. return sa; // expected-error {{use of undeclared identifier 'sa'}} } }; }; template struct D; } namespace PR19233 { template struct A : T { void foo() { ::undef(); // expected-error {{no member named 'undef' in the global namespace}} } void bar() { ::UndefClass::undef(); // expected-error {{no member named 'UndefClass' in the global namespace}} } void baz() { B::qux(); // expected-error {{use of undeclared identifier 'B'}} \ // expected-warning {{unqualified lookup into dependent bases of class template 'A'}} } }; struct B { void qux(); }; struct C : B { }; template struct A; // No error! B is a base of A, and qux is available. struct D { }; template struct A; // expected-note {{in instantiation of member function 'PR19233::A::baz' requested here}} } namespace nonmethod_missing_this { template struct Base { int y = 42; }; template struct Derived : Base { int x = y; // expected-warning {{lookup into dependent bases}} auto foo(int j) -> decltype(y * j) { // expected-warning {{lookup into dependent bases}} return y * j; // expected-warning {{lookup into dependent bases}} } int bar() { return [&] { return y; }(); // expected-warning {{lookup into dependent bases}} } }; template struct Derived; } namespace typedef_in_base { template struct A { typedef T NameFromBase; }; template struct B : A { NameFromBase m; // expected-warning {{found via unqualified lookup into dependent bases}} }; static_assert(sizeof(B) == 4, ""); } namespace struct_in_base { template struct A { struct NameFromBase {}; }; template struct B : A { NameFromBase m; // expected-warning {{found via unqualified lookup into dependent bases}} }; static_assert(sizeof(B) == 1, ""); } namespace enum_in_base { template struct A { enum NameFromBase { X }; }; template struct B : A { NameFromBase m; // expected-warning {{found via unqualified lookup into dependent bases}} }; static_assert(sizeof(B) == sizeof(A::NameFromBase), ""); } namespace two_types_in_base { template struct A { typedef T NameFromBase; }; // expected-note {{member found by ambiguous name lookup}} template struct B { struct NameFromBase { T m; }; }; // expected-note {{member found by ambiguous name lookup}} template struct C : A, B { 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}} }; static_assert(sizeof(C) != 0, ""); // expected-note {{in instantiation of template class 'two_types_in_base::C' requested here}} } namespace type_and_decl_in_base { template struct A { typedef T NameFromBase; }; template struct B { static const T NameFromBase = 42; }; template struct C : A, B { NameFromBase m; // expected-error {{unknown type name 'NameFromBase'}} }; } namespace classify_type_from_base { template struct A { struct NameFromBase {}; }; template struct B : A { A m; // expected-warning {{found via unqualified lookup into dependent bases}} }; } namespace classify_nontype_from_base { // MSVC does not do lookup of non-type declarations from dependent template base // classes. The extra lookup only applies to types. template struct A { void NameFromBase() {} }; template struct B { }; template struct C : A { B a; // correct B b; // expected-error {{use of undeclared identifier 'NameFromBase'}} }; } namespace template_in_base { template struct A { template struct NameFromBase { U x; }; }; template struct B : A { // Correct form. typename B::template NameFromBase m; }; template struct C : A { // Incorrect form. NameFromBase m; // expected-error {{unknown type name 'NameFromBase'}} //expected-error@-1 {{expected member name or ';' after declaration specifiers}} }; } namespace type_in_inner_class_in_base { template struct A { struct B { typedef T NameFromBase; }; }; template struct C : A::B { NameFromBase m; }; // expected-error {{unknown type name 'NameFromBase'}} } namespace type_in_inner_template_class_in_base { template struct A { template struct B { typedef U InnerType; }; }; template struct C : A::template B { NameFromBase m; // expected-error {{unknown type name 'NameFromBase'}} }; } namespace have_nondependent_base { template struct A { // Nothing, lookup should fail. }; template struct B : A { NameFromBase m; }; // expected-error {{unknown type name 'NameFromBase'}} struct C : A { NameFromBase m; }; // expected-error {{unknown type name 'NameFromBase'}} } namespace type_in_base_of_dependent_base { struct A { typedef int NameFromBase; }; template struct B : A {}; template struct C : B { NameFromBase m; }; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} } namespace type_in_second_dependent_base { template struct A {}; template struct B { typedef T NameFromBase; }; template struct D : A, B { NameFromBase m; }; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} } namespace type_in_second_non_dependent_base { struct A {}; struct B { typedef int NameFromBase; }; template struct C : A, B {}; template struct D : C { NameFromBase m; }; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} } namespace type_in_virtual_base_of_dependent_base { template struct A { typedef T NameFromBase; }; template struct B : virtual A {}; template struct C : B, virtual A { NameFromBase m; }; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} C c; } namespace type_in_base_of_multiple_dependent_bases { template struct A { typedef T NameFromBase; }; template struct B : public A {}; template struct C : B, public A { 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' is inaccessible due to ambiguity:}} C c; // expected-note {{in instantiation of template class 'type_in_base_of_multiple_dependent_bases::C' requested here}} } namespace type_in_dependent_base_of_non_dependent_type { template struct A { typedef int NameFromBase; }; template struct B : A { struct C; template struct D : C { NameFromBase m; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} }; struct E : C { NameFromBase m; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} }; }; template struct B::C : B { NameFromBase m; // expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} }; template struct F : B::C { NameFromBase m; // expected-error {{unknown type name 'NameFromBase'}} }; } namespace lookup_in_function_contexts { template struct A { typedef T NameFromBase; }; template struct B : A { // expected-warning@+1 {{lookup into dependent bases}} static auto lateSpecifiedFunc() -> decltype(NameFromBase()) { return {}; } static void memberFunc() { NameFromBase x; // expected-warning {{lookup into dependent bases}} } static void funcLocalClass() { struct X { NameFromBase x; // expected-warning {{lookup into dependent bases}} } y; } void localClassMethod() { struct X { void bar() { NameFromBase m; // expected-warning {{lookup into dependent bases}} } } x; x.bar(); } static void funcLambda() { auto l = []() { NameFromBase x; // expected-warning {{lookup into dependent bases}} }; l(); } static constexpr int constexprFunc() { NameFromBase x = {}; // expected-warning {{lookup into dependent bases}} return sizeof(x); } static auto autoFunc() { NameFromBase x; // expected-warning {{lookup into dependent bases}} return x; } }; // Force us to parse the methods. template struct B; } namespace function_template_deduction { // Overloaded function templates. template int f() { return N; } template int f() { return sizeof(T); } // Dependent base class with type. template struct A { typedef T NameFromBase; }; template struct B : A { // expected-warning@+1 {{found via unqualified lookup into dependent bases}} int x = f(); }; // Dependent base class with enum. template struct C { enum { NameFromBase = 4 }; }; template struct D : C { // expected-warning@+1 {{use of undeclared identifier 'NameFromBase'; unqualified lookup into dependent bases}} int x = f(); }; } namespace function_template_undef_impl { template void f() { Undef::staticMethod(); // expected-error {{use of undeclared identifier 'Undef'}} UndefVar.method(); // expected-error {{use of undeclared identifier 'UndefVar'}} } } namespace PR20716 { template