1 // RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -triple %ms_abi_triple -DMSABI -fsyntax-only -verify %s
3 
4 namespace PR5557 {
5 template <class T> struct A {
6   A();
7   virtual void anchor();
8   virtual int a(T x);
9 };
10 template<class T> A<T>::A() {}
11 template<class T> void A<T>::anchor() { }
12 
13 template<class T> int A<T>::a(T x) {
14   return *x; // expected-error{{requires pointer operand}}
15 }
16 
17 void f(A<int> x) {
18   x.anchor(); // expected-note{{instantiation}}
19 }
20 
21 template<typename T>
22 struct X {
23   virtual void f();
24 };
25 
26 template<>
27 void X<int>::f() { }
28 }
29 
30 template<typename T>
31 struct Base {
32   virtual ~Base() {
33     int *ptr = 0;
34     T t = ptr; // expected-error{{cannot initialize}}
35   }
36 };
37 
38 template<typename T>
39 struct Derived : Base<T> {
40   virtual void foo() { }
41 };
42 
43 template struct Derived<int>; // expected-note {{in instantiation of member function 'Base<int>::~Base' requested here}}
44 
45 template<typename T>
46 struct HasOutOfLineKey {
47   HasOutOfLineKey() { } // expected-note{{in instantiation of member function 'HasOutOfLineKey<int>::f' requested here}}
48   virtual T *f(float *fp);
49 };
50 
51 template<typename T>
52 T *HasOutOfLineKey<T>::f(float *fp) {
53   return fp; // expected-error{{cannot initialize return object of type 'int *' with an lvalue of type 'float *'}}
54 }
55 
56 HasOutOfLineKey<int> out_of_line; // expected-note{{in instantiation of member function 'HasOutOfLineKey<int>::HasOutOfLineKey' requested here}}
57 
58 namespace std {
59   class type_info;
60 }
61 
62 namespace PR7114 {
63   class A { virtual ~A(); }; // expected-note{{declared private here}}
64 
65   template<typename T>
66   class B {
67   public:
68     class Inner : public A { }; // expected-error{{base class 'PR7114::A' has private destructor}}
69     static Inner i;
70     static const unsigned value = sizeof(i) == 4;
71   };
72 
73   int f() { return B<int>::value; }
74 
75 #ifdef MSABI
76   void test_typeid(B<float>::Inner bfi) { // expected-note{{implicit destructor}}
77     (void)typeid(bfi);
78 #else
79   void test_typeid(B<float>::Inner bfi) {
80     (void)typeid(bfi); // expected-note{{implicit destructor}}
81 #endif
82   }
83 
84   template<typename T>
85   struct X : A {
86     void f() { }
87   };
88 
89   void test_X(X<int> &xi, X<float> &xf) {
90     xi.f();
91   }
92 }
93 
94 namespace DynamicCast {
95   struct Y {};
96   template<typename T> struct X : virtual Y {
97     virtual void foo() { T x; } // expected-error {{variable has incomplete type 'void'}}
98   };
99   template<typename T> struct X2 : virtual Y {
100     virtual void foo() { T x; }
101   };
102   Y* f(X<void>* x) { return dynamic_cast<Y*>(x); } // expected-note {{in instantiation of member function 'DynamicCast::X<void>::foo' requested here}}
103   Y* f2(X<void>* x) { return dynamic_cast<Y*>(x); }
104 }
105 
106 namespace avoid_using_vtable {
107 // We shouldn't emit the vtable for this code, in any ABI.  If we emit the
108 // vtable, we emit an implicit virtual dtor, which calls ~RefPtr, which requires
109 // a complete type for DeclaredOnly.
110 //
111 // Previously we would reference the vtable in the MS C++ ABI, even though we
112 // don't need to emit either the ctor or the dtor.  In the Itanium C++ ABI, the
113 // 'trace' method is the key function, so even though we use the vtable, we
114 // don't emit it.
115 
116 template <typename T>
117 struct RefPtr {
118   T *m_ptr;
119   ~RefPtr() { m_ptr->deref(); }
120 };
121 struct DeclaredOnly;
122 struct Base {
123   virtual ~Base();
124 };
125 
126 struct AvoidVTable : Base {
127   RefPtr<DeclaredOnly> m_insertionStyle;
128   virtual void trace();
129   AvoidVTable();
130 };
131 // Don't call the dtor, because that will emit an implicit dtor, and require a
132 // complete type for DeclaredOnly.
133 void foo() { new AvoidVTable; }
134 }
135 
136 namespace vtable_uses_incomplete {
137 // Opposite of the previous test that avoids a vtable, this one tests that we
138 // use the vtable when the ctor is defined inline.
139 template <typename T>
140 struct RefPtr {
141   T *m_ptr;
142   ~RefPtr() { m_ptr->deref(); }  // expected-error {{member access into incomplete type 'vtable_uses_incomplete::DeclaredOnly'}}
143 };
144 struct DeclaredOnly; // expected-note {{forward declaration of 'vtable_uses_incomplete::DeclaredOnly'}}
145 struct Base {
146   virtual ~Base();
147 };
148 
149 struct UsesVTable : Base {
150   RefPtr<DeclaredOnly> m_insertionStyle;
151   virtual void trace();
152   UsesVTable() {} // expected-note {{in instantiation of member function 'vtable_uses_incomplete::RefPtr<vtable_uses_incomplete::DeclaredOnly>::~RefPtr' requested here}}
153 };
154 }
155