2014-06-11 08:01:28 +08:00
// RUN: %clang_cc1 -std=c++11 -fms-compatibility -fsyntax-only -verify %s
2011-09-07 08:14:57 +08:00
template < class T >
class A {
public :
void f ( T a ) { } // expected-note {{must qualify identifier to find this declaration in dependent base class}}
void g ( ) ; // expected-note {{must qualify identifier to find this declaration in dependent base class}}
} ;
template < class T >
class B : public A < T > {
public :
void z ( T a )
{
f ( a ) ; // expected-warning {{use of identifier 'f' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
g ( ) ; // expected-warning {{use of identifier 'g' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
}
} ;
template class B < int > ; // expected-note {{requested here}}
template class B < char > ;
void test ( )
{
B < int > b ;
b . z ( 3 ) ;
}
2013-04-29 16:45:27 +08:00
struct A2 {
template < class T > 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 < class T0 >
struct A3 {
template < class T1 > void f ( T1 ) {
XX ; //expected-error {{use of undeclared identifier 'XX'}}
}
} ;
template void A3 < int > : : f ( int ) ;
template < class T0 >
struct A4 {
void f ( char ) {
XX ; //expected-error {{use of undeclared identifier 'XX'}}
}
} ;
template class A4 < int > ;
2011-11-11 08:12:11 +08:00
namespace lookup_dependent_bases_id_expr {
template < class T > class A {
public :
int var ;
} ;
template < class T >
class B : public A < T > {
public :
void f ( ) {
2014-06-11 08:01:28 +08:00
var = 3 ; // expected-warning {{use of undeclared identifier 'var'; unqualified lookup into dependent bases of class template 'B' is a Microsoft extension}}
2011-11-11 08:12:11 +08:00
}
} ;
template class B < int > ;
}
2011-09-07 08:14:57 +08:00
2011-11-16 07:33:34 +08:00
namespace lookup_dependent_base_class_static_function {
template < class T >
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 T >
class B : public A < T > {
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}}
2011-11-17 11:44:24 +08:00
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}}
2011-11-16 07:33:34 +08:00
}
} ;
template class B < int > ; // expected-note {{requested here}}
}
2011-11-17 11:44:24 +08:00
namespace lookup_dependent_base_class_default_argument {
template < class T >
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 T >
class B : public A < T > {
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 < int > b ;
b . g1 ( ) ; // expected-note {{required here}}
b . g2 ( ) ; // expected-note {{required here}}
}
2011-11-25 09:10:54 +08:00
}
namespace lookup_dependent_base_class_friend {
template < class T >
class B {
public :
static void g ( ) ; // expected-note {{must qualify identifier to find this declaration in dependent base class}}
} ;
template < class T >
class A : public B < T > {
public :
friend void foo ( A < T > 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 < int > a ;
foo ( a ) ; // expected-note {{requested here}}
}
}
2011-12-03 23:55:29 +08:00
namespace lookup_dependent_base_no_typo_correction {
class C {
public :
int m_hWnd ;
} ;
template < class T >
class A : public T {
public :
void f ( int hWnd ) {
2014-06-11 08:01:28 +08:00
m_hWnd = 1 ; // expected-warning {{use of undeclared identifier 'm_hWnd'; unqualified lookup into dependent bases of class template 'A' is a Microsoft extension}}
2011-12-03 23:55:29 +08:00
}
} ;
template class A < C > ;
}
2012-06-21 04:21:42 +08:00
namespace PR12701 {
class A { } ;
class B { } ;
template < class T >
class Base {
public :
2013-12-06 00:25:25 +08:00
bool base_fun ( void * p ) { return false ; } // expected-note {{must qualify identifier to find this declaration in dependent base class}}
2012-06-21 04:21:42 +08:00
operator T * ( ) const { return 0 ; }
} ;
template < class T >
class Container : public Base < T > {
public :
template < typename S >
bool operator = ( const Container < S > & 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 < A > text_provider ;
Container < B > text_provider2 ;
text_provider2 = text_provider ; // expected-note {{in instantiation of function template specialization}}
}
} // namespace PR12701
2013-10-16 02:38:02 +08:00
namespace PR16014 {
struct A {
int a ;
static int sa ;
} ;
template < typename T > struct B : T {
2014-06-11 08:01:28 +08:00
int foo ( ) { return a ; } // expected-warning {{lookup into dependent bases}}
int * bar ( ) { return & a ; } // expected-warning {{lookup into dependent bases}}
2013-10-16 02:38:02 +08:00
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 ; }
2014-06-11 08:01:28 +08:00
static int stuff3 ( ) { return sa ; } // expected-warning {{lookup into dependent bases}}
static int * stuff4 ( ) { return & sa ; } // expected-warning {{lookup into dependent bases}}
2013-10-16 02:38:02 +08:00
} ;
template < typename T > struct C : T {
2014-06-11 08:01:28 +08:00
int foo ( ) { return b ; } // expected-error {{no member named 'b' in 'PR16014::C<PR16014::A>'}} expected-warning {{lookup into dependent bases}}
int * bar ( ) { return & b ; } // expected-error {{no member named 'b' in 'PR16014::C<PR16014::A>'}} expected-warning {{lookup into dependent bases}}
2013-10-16 02:38:02 +08:00
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'}}
} ;
template struct B < A > ;
2013-12-14 09:07:05 +08:00
template struct C < A > ; // expected-note-re 1+ {{in instantiation of member function 'PR16014::C<PR16014::A>::{{.*}}' requested here}}
2013-10-16 02:38:02 +08:00
template < typename T > 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 < A > ;
}
2014-03-26 04:31:28 +08:00
namespace PR19233 {
template < class T >
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'}}
}
} ;
struct B { void qux ( ) ; } ;
struct C : B { } ;
template struct A < C > ; // No error! B is a base of A<C>, and qux is available.
struct D { } ;
template struct A < D > ; // expected-note {{in instantiation of member function 'PR19233::A<PR19233::D>::baz' requested here}}
}
2014-06-11 08:01:28 +08:00
namespace nonmethod_missing_this {
template < typename T > struct Base { int y = 42 ; } ;
template < typename T > struct Derived : Base < T > {
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 < int > ;
}