1 // RUN: %clang_cc1 -fsyntax-only -triple %itanium_abi_triple -verify %s -std=c++11
2 // RUN: %clang_cc1 -fsyntax-only -triple %ms_abi_triple -verify %s -std=c++11
6 virtual int f(); // expected-note{{overridden virtual function is here}}
10 virtual void f(); // expected-error{{virtual function 'f' has a different return type ('void') than the function it overrides (which has return type 'int')}}
21 virtual a
* f(); // expected-note{{overridden virtual function is here}}
25 virtual b
* f(); // expected-error{{return type of virtual function 'f' is not covariant with the return type of the function it overrides ('b *' is not derived from 'a *')}}
33 struct b
: private a
{ }; // expected-note{{declared private here}}
36 virtual a
* f(); // FIXME: desired-note{{overridden virtual function is here}}
40 virtual b
* f(); // expected-error{{invalid covariant return for virtual function: 'a' is a private base class of 'b'}}
49 struct b
: a
, a1
{ }; // expected-warning{{direct base 'a' is inaccessible due to ambiguity:\n struct T4::b -> a\n struct T4::b -> a1 -> a}}
52 virtual a
* f(); // expected-note{{overridden virtual function is here}}
56 virtual b
* f(); // expected-error{{return type of virtual function 'f' is not covariant with the return type of the function it overrides (ambiguous conversion from derived class 'b' to base class 'a':\n\
58 struct T4::b
-> a1
-> a
)}}
69 virtual a
* const g(); // expected-note{{overridden virtual function is here}}
74 virtual a
* g(); // expected-error{{return type of virtual function 'g' is not covariant with the return type of the function it overrides ('a *' has different qualifiers than 'a *const')}}
85 virtual a
* g(); // expected-note{{overridden virtual function is here}}
90 virtual const a
* g(); // expected-error{{return type of virtual function 'g' is not covariant with the return type of the function it overrides (class type 'const a *' is more qualified than class type 'a *'}}
110 struct b
; // expected-note {{forward declaration of 'T8::b'}}
117 b
* f(); // expected-error {{return type of virtual function 'f' is not covariant with the return type of the function it overrides ('b' is incomplete)}}
124 template<typename T
> struct b
: a
{
125 int a
[sizeof(T
) ? -1 : -1]; // expected-error {{array with a negative size}}
133 virtual b
<int> *f(); // expected-note {{in instantiation of template class 'T9::b<int>' requested here}}
141 class X1
: public X0
{
145 template <typename Base
>
147 void f(int) = 0; // expected-error{{not virtual and cannot be declared pure}}
150 struct Base1
{ virtual void f(int); };
154 (void)sizeof(Foo
<Base1
>);
155 (void)sizeof(Foo
<Base2
>); // expected-note{{instantiation}}
158 template<typename Base
>
160 template<typename T
> int f(T
);
171 virtual void f(int) = 0; // expected-note{{unimplemented pure virtual method}}
180 Bar3
<int> b3i
; // okay
181 Bar3
<float> b3f
; // expected-error{{is an abstract class}}
188 template <typename T
>
189 class Derived
: public Base
{};
193 virtual Base
* Method();
196 class Bar
: public Foo
{
198 virtual Derived
<int>* Method();
202 // Look through template types and typedefs to see whether return types are
203 // pointers or references.
206 class Derived
: public Base
{};
209 typedef Derived
* DerivedP
;
211 class X
{ virtual BaseP
f(); };
212 class X1
: public X
{ virtual DerivedP
f(); };
214 template <typename T
> class Y
{ virtual T
f(); };
215 template <typename T1
, typename T
> class Y1
: public Y
<T
> { virtual T1
f(); };
216 Y1
<Derived
*, Base
*> y
;
219 // Defer checking for covariance if either return type is dependent.
220 namespace type_dependent_covariance
{
222 template <int N
> struct TD
: public B
{};
223 template <> struct TD
<1> {};
225 template <int N
> struct TB
{};
226 struct D
: public TB
<0> {};
228 template <int N
> struct X
{
229 virtual B
* f1(); // expected-note{{overridden virtual function is here}}
230 virtual TB
<N
>* f2(); // expected-note{{overridden virtual function is here}}
232 template <int N
, int M
> struct X1
: X
<N
> {
233 virtual TD
<M
>* f1(); // expected-error{{return type of virtual function 'f1' is not covariant with the return type of the function it overrides ('TD<1> *'}}
234 virtual D
* f2(); // expected-error{{return type of virtual function 'f2' is not covariant with the return type of the function it overrides ('D *' is not derived from 'TB<1> *')}}
238 X1
<0, 1> bad_derived
; // expected-note{{instantiation}}
239 X1
<1, 0> bad_base
; // expected-note{{instantiation}}
260 virtual A
& f(); // expected-note {{overridden virtual function is here}}
264 virtual B
&& f(); // expected-error {{virtual function 'f' has a different return type ('B &&') than the function it overrides (which has return type 'A &')}}
273 virtual A
&& f(); // expected-note {{overridden virtual function is here}}
277 virtual B
& f(); // expected-error {{virtual function 'f' has a different return type ('B &') than the function it overrides (which has return type 'A &&')}}
284 virtual void foo() {} // expected-note{{overridden virtual function is here}}
289 static void foo() {} // expected-error{{'static' member function 'foo' overrides a virtual function}}