blob: 974f66484ba151aa05179e18438861077ceecd2f [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Anders Carlsson863dbcb2009-12-07 08:29:39 +00002
3namespace PR5557 {
4template <class T> struct A {
5 A();
Douglas Gregor6fb745b2010-05-13 16:44:06 +00006 virtual void anchor();
Anders Carlsson863dbcb2009-12-07 08:29:39 +00007 virtual int a(T x);
8};
9template<class T> A<T>::A() {}
Douglas Gregor159ef1e2010-01-06 04:44:19 +000010template<class T> void A<T>::anchor() { }
11
Anders Carlsson863dbcb2009-12-07 08:29:39 +000012template<class T> int A<T>::a(T x) {
13 return *x; // expected-error{{requires pointer operand}}
14}
15
Douglas Gregor159ef1e2010-01-06 04:44:19 +000016void f(A<int> x) {
Douglas Gregor6fb745b2010-05-13 16:44:06 +000017 x.anchor(); // expected-note{{instantiation}}
Douglas Gregor159ef1e2010-01-06 04:44:19 +000018}
Anders Carlsson863dbcb2009-12-07 08:29:39 +000019
20template<typename T>
21struct X {
22 virtual void f();
23};
24
25template<>
26void X<int>::f() { }
27}
Douglas Gregor159ef1e2010-01-06 04:44:19 +000028
29template<typename T>
30struct Base {
31 virtual ~Base() {
32 int *ptr = 0;
33 T t = ptr; // expected-error{{cannot initialize}}
34 }
35};
36
37template<typename T>
38struct Derived : Base<T> {
John McCall6c790ea2010-03-16 05:36:30 +000039 virtual void foo() { }
Douglas Gregor159ef1e2010-01-06 04:44:19 +000040};
41
John McCall6c790ea2010-03-16 05:36:30 +000042template struct Derived<int>; // expected-note {{in instantiation of member function 'Base<int>::~Base' requested here}}
Douglas Gregor159ef1e2010-01-06 04:44:19 +000043
Douglas Gregor4b0f21c2010-01-06 20:27:16 +000044template<typename T>
45struct HasOutOfLineKey {
Douglas Gregor6fb745b2010-05-13 16:44:06 +000046 HasOutOfLineKey() { }
Douglas Gregor4b0f21c2010-01-06 20:27:16 +000047 virtual T *f(float *fp);
48};
49
50template<typename T>
51T *HasOutOfLineKey<T>::f(float *fp) {
52 return fp; // expected-error{{cannot initialize return object of type 'int *' with an lvalue of type 'float *'}}
53}
54
Douglas Gregor6fb745b2010-05-13 16:44:06 +000055HasOutOfLineKey<int> out_of_line; // expected-note{{in instantiation of member function 'HasOutOfLineKey<int>::f' requested here}}
56
57namespace std {
58 class type_info;
59}
60
61namespace PR7114 {
62 class A { virtual ~A(); }; // expected-note{{declared private here}}
63
64 template<typename T>
65 class B {
66 public:
67 class Inner : public A { }; // expected-error{{base class 'PR7114::A' has private destructor}}
68 static Inner i;
69 static const unsigned value = sizeof(i) == 4;
70 };
71
72 int f() { return B<int>::value; }
73
74 void test_typeid(B<float>::Inner bfi) {
75 (void)typeid(bfi); // expected-note{{implicit default destructor}}
76 }
77
78 template<typename T>
79 struct X : A {
80 void f() { }
81 };
82
83 void test_X(X<int> xi, X<float> xf) {
84 xi.f();
85 }
86}