1 // RUN: %clang_cc1 -fsyntax-only -faccess-control -verify %s -std=c++0x
5 virtual int f(); // expected-note{{overridden virtual function is here}}
9 virtual void f(); // expected-error{{virtual function 'f' has a different return type ('void') than the function it overrides (which has return type 'int')}}
20 virtual a* f(); // expected-note{{overridden virtual function is here}}
24 virtual b* f(); // expected-error{{return type of virtual function 'f' is not covariant with the return type of the function it overrides ('struct T2::b *' is not derived from 'struct T2::a *')}}
32 struct b : private a { }; // expected-note{{declared private here}}
35 virtual a* f(); // expected-note{{overridden virtual function is here}}
39 virtual b* f(); // expected-error{{invalid covariant return for virtual function: 'struct T3::a' is a private base class of 'struct T3::b'}}
51 virtual a* f(); // expected-note{{overridden virtual function is here}}
55 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 'struct T4::b' to base class 'struct T4::a':\n\
56 struct T4::b -> struct T4::a\n\
57 struct T4::b -> struct T4::a1 -> struct T4::a)}}
68 virtual a* const g(); // expected-note{{overridden virtual function is here}}
73 virtual a* g(); // expected-error{{return type of virtual function 'g' is not covariant with the return type of the function it overrides ('struct T5::a *' has different qualifiers than 'struct T5::a *const')}}
84 virtual a* g(); // expected-note{{overridden virtual function is here}}
89 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 'struct T6::a const *' is more qualified than class type 'struct T6::a *'}}
109 struct b; // expected-note {{forward declaration of 'struct T8::b'}}
116 b* f(); // expected-error {{return type of virtual function 'f' is not covariant with the return type of the function it overrides ('struct T8::b' is incomplete)}}
123 template<typename T> struct b : a {
124 int a[sizeof(T) ? -1 : -1]; // expected-error {{array size is negative}}
132 virtual b<int> *f(); // expected-note {{in instantiation of template class 'struct T9::b<int>' requested here}}
140 class X1 : public X0 {
144 template <typename Base>
146 void f(int) = 0; // expected-error{{not virtual and cannot be declared pure}}
149 struct Base1 { virtual void f(int); };
153 (void)sizeof(Foo<Base1>);
154 (void)sizeof(Foo<Base2>); // expected-note{{instantiation}}
157 template<typename Base>
159 template<typename T> int f(T);
170 virtual void f(int) = 0; // expected-note{{pure virtual function}}
179 Bar3<int> b3i; // okay
180 Bar3<float> b3f; // expected-error{{is an abstract class}}
187 template <typename T>
188 class Derived : public Base {};
192 virtual Base* Method();
195 class Bar : public Foo {
197 virtual Derived<int>* Method();
201 // Look through template types and typedefs to see whether return types are
202 // pointers or references.
205 class Derived : public Base {};
208 typedef Derived* DerivedP;
210 class X { virtual BaseP f(); };
211 class X1 : public X { virtual DerivedP f(); };
213 template <typename T> class Y { virtual T f(); };
214 template <typename T1, typename T> class Y1 : public Y<T> { virtual T1 f(); };
215 Y1<Derived*, Base*> y;
218 // Defer checking for covariance if either return type is dependent.
219 namespace type_dependent_covariance {
221 template <int N> struct TD : public B {};
222 template <> struct TD<1> {};
224 template <int N> struct TB {};
225 struct D : public TB<0> {};
227 template <int N> struct X {
228 virtual B* f1(); // expected-note{{overridden virtual function is here}}
229 virtual TB<N>* f2(); // expected-note{{overridden virtual function is here}}
231 template <int N, int M> struct X1 : X<N> {
232 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> *'}}
233 virtual D* f2(); // expected-error{{return type of virtual function 'f2' is not covariant with the return type of the function it overrides ('struct type_dependent_covariance::D *' is not derived from 'TB<1> *')}}
237 X1<0, 1> bad_derived; // expected-note{{instantiation}}
238 X1<1, 0> bad_base; // expected-note{{instantiation}}
259 virtual A& f(); // expected-note {{overridden virtual function is here}}
263 virtual B&& f(); // expected-error {{virtual function 'f' has a different return type ('struct T11::B &&') than the function it overrides (which has return type 'struct T11::A &')}}
272 virtual A&& f(); // expected-note {{overridden virtual function is here}}
276 virtual B& f(); // expected-error {{virtual function 'f' has a different return type ('struct T12::B &') than the function it overrides (which has return type 'struct T12::A &&')}}