1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc namespace PR5557 { 4*f4a2713aSLionel Sambuc template <class T> struct A { 5*f4a2713aSLionel Sambuc A(); 6*f4a2713aSLionel Sambuc virtual void anchor(); 7*f4a2713aSLionel Sambuc virtual int a(T x); 8*f4a2713aSLionel Sambuc }; 9*f4a2713aSLionel Sambuc template<class T> A<T>::A() {} 10*f4a2713aSLionel Sambuc template<class T> void A<T>::anchor() { } 11*f4a2713aSLionel Sambuc 12*f4a2713aSLionel Sambuc template<class T> int A<T>::a(T x) { 13*f4a2713aSLionel Sambuc return *x; // expected-error{{requires pointer operand}} 14*f4a2713aSLionel Sambuc } 15*f4a2713aSLionel Sambuc 16*f4a2713aSLionel Sambuc void f(A<int> x) { 17*f4a2713aSLionel Sambuc x.anchor(); // expected-note{{instantiation}} 18*f4a2713aSLionel Sambuc } 19*f4a2713aSLionel Sambuc 20*f4a2713aSLionel Sambuc template<typename T> 21*f4a2713aSLionel Sambuc struct X { 22*f4a2713aSLionel Sambuc virtual void f(); 23*f4a2713aSLionel Sambuc }; 24*f4a2713aSLionel Sambuc 25*f4a2713aSLionel Sambuc template<> 26*f4a2713aSLionel Sambuc void X<int>::f() { } 27*f4a2713aSLionel Sambuc } 28*f4a2713aSLionel Sambuc 29*f4a2713aSLionel Sambuc template<typename T> 30*f4a2713aSLionel Sambuc struct Base { 31*f4a2713aSLionel Sambuc virtual ~Base() { 32*f4a2713aSLionel Sambuc int *ptr = 0; 33*f4a2713aSLionel Sambuc T t = ptr; // expected-error{{cannot initialize}} 34*f4a2713aSLionel Sambuc } 35*f4a2713aSLionel Sambuc }; 36*f4a2713aSLionel Sambuc 37*f4a2713aSLionel Sambuc template<typename T> 38*f4a2713aSLionel Sambuc struct Derived : Base<T> { 39*f4a2713aSLionel Sambuc virtual void foo() { } 40*f4a2713aSLionel Sambuc }; 41*f4a2713aSLionel Sambuc 42*f4a2713aSLionel Sambuc template struct Derived<int>; // expected-note {{in instantiation of member function 'Base<int>::~Base' requested here}} 43*f4a2713aSLionel Sambuc 44*f4a2713aSLionel Sambuc template<typename T> 45*f4a2713aSLionel Sambuc struct HasOutOfLineKey { 46*f4a2713aSLionel Sambuc HasOutOfLineKey() { } 47*f4a2713aSLionel Sambuc virtual T *f(float *fp); 48*f4a2713aSLionel Sambuc }; 49*f4a2713aSLionel Sambuc 50*f4a2713aSLionel Sambuc template<typename T> 51*f4a2713aSLionel Sambuc T *HasOutOfLineKey<T>::f(float *fp) { 52*f4a2713aSLionel Sambuc return fp; // expected-error{{cannot initialize return object of type 'int *' with an lvalue of type 'float *'}} 53*f4a2713aSLionel Sambuc } 54*f4a2713aSLionel Sambuc 55*f4a2713aSLionel Sambuc HasOutOfLineKey<int> out_of_line; // expected-note{{in instantiation of member function 'HasOutOfLineKey<int>::f' requested here}} 56*f4a2713aSLionel Sambuc 57*f4a2713aSLionel Sambuc namespace std { 58*f4a2713aSLionel Sambuc class type_info; 59*f4a2713aSLionel Sambuc } 60*f4a2713aSLionel Sambuc 61*f4a2713aSLionel Sambuc namespace PR7114 { 62*f4a2713aSLionel Sambuc class A { virtual ~A(); }; // expected-note{{declared private here}} 63*f4a2713aSLionel Sambuc 64*f4a2713aSLionel Sambuc template<typename T> 65*f4a2713aSLionel Sambuc class B { 66*f4a2713aSLionel Sambuc public: 67*f4a2713aSLionel Sambuc class Inner : public A { }; // expected-error{{base class 'PR7114::A' has private destructor}} 68*f4a2713aSLionel Sambuc static Inner i; 69*f4a2713aSLionel Sambuc static const unsigned value = sizeof(i) == 4; 70*f4a2713aSLionel Sambuc }; 71*f4a2713aSLionel Sambuc 72*f4a2713aSLionel Sambuc int f() { return B<int>::value; } 73*f4a2713aSLionel Sambuc 74*f4a2713aSLionel Sambuc void test_typeid(B<float>::Inner bfi) { 75*f4a2713aSLionel Sambuc (void)typeid(bfi); // expected-note{{implicit destructor}} 76*f4a2713aSLionel Sambuc } 77*f4a2713aSLionel Sambuc 78*f4a2713aSLionel Sambuc template<typename T> 79*f4a2713aSLionel Sambuc struct X : A { 80*f4a2713aSLionel Sambuc void f() { } 81*f4a2713aSLionel Sambuc }; 82*f4a2713aSLionel Sambuc 83*f4a2713aSLionel Sambuc void test_X(X<int> xi, X<float> xf) { 84*f4a2713aSLionel Sambuc xi.f(); 85*f4a2713aSLionel Sambuc } 86*f4a2713aSLionel Sambuc } 87*f4a2713aSLionel Sambuc 88*f4a2713aSLionel Sambuc namespace DynamicCast { 89*f4a2713aSLionel Sambuc struct Y {}; 90*f4a2713aSLionel Sambuc template<typename T> struct X : virtual Y { 91*f4a2713aSLionel Sambuc virtual void foo() { T x; } // expected-error {{variable has incomplete type 'void'}} 92*f4a2713aSLionel Sambuc }; 93*f4a2713aSLionel Sambuc template<typename T> struct X2 : virtual Y { 94*f4a2713aSLionel Sambuc virtual void foo() { T x; } 95*f4a2713aSLionel Sambuc }; 96*f4a2713aSLionel Sambuc Y* f(X<void>* x) { return dynamic_cast<Y*>(x); } // expected-note {{in instantiation of member function 'DynamicCast::X<void>::foo' requested here}} 97*f4a2713aSLionel Sambuc Y* f2(X<void>* x) { return dynamic_cast<Y*>(x); } 98*f4a2713aSLionel Sambuc } 99