1 // RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -verify -std=c++11 %s
4 // RUN: %clang_cc1 -triple %ms_abi_triple -DMSABI -fsyntax-only -verify %s
5 // RUN: %clang_cc1 -triple %ms_abi_triple -DMSABI -fsyntax-only -std=c++98 -verify %s
6 // RUN: %clang_cc1 -triple %ms_abi_triple -DMSABI -fsyntax-only -std=c++11 -verify %s
9 template <class T
> struct A
{
10 A(); // expected-note{{instantiation}}
13 template<class T
> A
<T
>::A() {}
15 template<class T
> int A
<T
>::a(T x
) {
16 return *x
; // expected-error{{requires pointer operand}}
20 A
<int> x
; // expected-note{{instantiation}}
32 // Like PR5557, but with a defined destructor instead of a defined constructor.
33 namespace PR5557_dtor
{
34 template <class T
> struct A
{
35 A(); // Don't have an implicit constructor.
36 ~A(); // expected-note{{instantiation}}
39 template<class T
> A
<T
>::~A() {}
41 template<class T
> int A
<T
>::a(T x
) {
42 return *x
; // expected-error{{requires pointer operand}}
46 A
<int> x
; // expected-note{{instantiation}}
54 T t
= ptr
; // expected-error{{cannot initialize}}
59 struct Derived
: Base
<T
> {
60 virtual void foo() { }
63 template struct Derived
<int>; // expected-note {{in instantiation of member function 'Base<int>::~Base' requested here}}
66 struct HasOutOfLineKey
{
67 HasOutOfLineKey() { } // expected-note{{in instantiation of member function 'HasOutOfLineKey<int>::f' requested here}}
68 virtual T
*f(float *fp
);
72 T
*HasOutOfLineKey
<T
>::f(float *fp
) {
73 return fp
; // expected-error{{cannot initialize return object of type 'int *' with an lvalue of type 'float *'}}
76 HasOutOfLineKey
<int> out_of_line
; // expected-note{{in instantiation of member function 'HasOutOfLineKey<int>::HasOutOfLineKey' requested here}}
83 class A
{ virtual ~A(); };
84 #if __cplusplus <= 199711L
85 // expected-note@-2{{declared private here}}
87 // expected-note@-4 3 {{overridden virtual function is here}}
93 class Inner
: public A
{ };
94 #if __cplusplus <= 199711L
95 // expected-error@-2{{base class 'A' has private destructor}}
97 // expected-error@-4 2 {{deleted function '~Inner' cannot override a non-deleted function}}
98 // expected-note@-5 2 {{destructor of 'Inner' is implicitly deleted because base class 'A' has an inaccessible destructor}}
100 // expected-note@-7 1 {{destructor of 'Inner' is implicitly deleted because base class 'A' has an inaccessible destructor}}
105 static const unsigned value
= sizeof(i
) == 4;
106 #if __cplusplus >= 201103L
107 // expected-note@-2 {{in instantiation of member class 'PR7114::B<int>::Inner' requested here}}
108 // expected-note@-3 {{in instantiation of member class 'PR7114::B<float>::Inner' requested here}}
112 int f() { return B
<int>::value
; }
113 #if __cplusplus >= 201103L
114 // expected-note@-2 {{in instantiation of template class 'PR7114::B<int>' requested here}}
118 void test_typeid(B
<float>::Inner bfi
) {
119 #if __cplusplus <= 199711L
120 // expected-note@-2 {{implicit destructor}}
122 // expected-error@-4 {{attempt to use a deleted function}}
123 // expected-note@-5 {{in instantiation of template class 'PR7114::B<float>' requested here}}
128 void test_typeid(B
<float>::Inner bfi
) {
129 #if __cplusplus >= 201103L
130 // expected-note@-2 {{in instantiation of template class 'PR7114::B<float>' requested here}}
133 #if __cplusplus <= 199711L
134 // expected-note@-2 {{implicit destructor}}
141 #if __cplusplus >= 201103L
142 // expected-error@-2 {{deleted function '~X' cannot override a non-deleted function}}
143 // expected-note@-3 {{destructor of 'X<int>' is implicitly deleted because base class 'A' has an inaccessible destructor}}
148 void test_X(X
<int> &xi
, X
<float> &xf
) {
150 #if __cplusplus >= 201103L
151 // expected-note@-2 {{in instantiation of template class 'PR7114::X<int>' requested here}}
156 namespace DynamicCast
{
158 template<typename T
> struct X
: virtual Y
{
159 virtual void foo() { T x
; }
161 template<typename T
> struct X2
: virtual Y
{
162 virtual void foo() { T x
; }
164 Y
* f(X
<void>* x
) { return dynamic_cast<Y
*>(x
); }
165 Y
* f2(X
<void>* x
) { return dynamic_cast<Y
*>(x
); }
168 namespace avoid_using_vtable
{
169 // We shouldn't emit the vtable for this code, in any ABI. If we emit the
170 // vtable, we emit an implicit virtual dtor, which calls ~RefPtr, which requires
171 // a complete type for DeclaredOnly.
173 // Previously we would reference the vtable in the MS C++ ABI, even though we
174 // don't need to emit either the ctor or the dtor. In the Itanium C++ ABI, the
175 // 'trace' method is the key function, so even though we use the vtable, we
178 template <typename T
>
181 ~RefPtr() { m_ptr
->deref(); }
188 struct AvoidVTable
: Base
{
189 RefPtr
<DeclaredOnly
> m_insertionStyle
;
190 virtual void trace();
193 // Don't call the dtor, because that will emit an implicit dtor, and require a
194 // complete type for DeclaredOnly.
195 void foo() { new AvoidVTable
; }
198 namespace vtable_uses_incomplete
{
199 // Opposite of the previous test that avoids a vtable, this one tests that we
200 // use the vtable when the ctor is defined inline.
201 template <typename T
>
204 ~RefPtr() { m_ptr
->deref(); } // expected-error {{member access into incomplete type 'vtable_uses_incomplete::DeclaredOnly'}}
206 struct DeclaredOnly
; // expected-note {{forward declaration of 'vtable_uses_incomplete::DeclaredOnly'}}
211 struct UsesVTable
: Base
{
212 RefPtr
<DeclaredOnly
> m_insertionStyle
;
213 virtual void trace();
214 UsesVTable() {} // expected-note {{in instantiation of member function 'vtable_uses_incomplete::RefPtr<vtable_uses_incomplete::DeclaredOnly>::~RefPtr' requested here}}