blob: c18a77f036bb65b487eadd983475671838d65ad0 [file] [log] [blame]
Anders Carlssonc3a68b22009-05-14 19:52:19 +00001// RUN: clang-cc -fsyntax-only -faccess-control -verify %s
Anders Carlssond7ba27d2009-05-14 01:09:04 +00002namespace T1 {
3
4class A {
5 virtual int f(); // expected-note{{overridden virtual function is here}}
6};
7
8class B : A {
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')}}
10};
11
12}
Anders Carlssonc3a68b22009-05-14 19:52:19 +000013
14namespace T2 {
15
16struct a { };
17struct b { };
18
19class A {
20 virtual a* f(); // expected-note{{overridden virtual function is here}}
21};
22
23class B : A {
Anders Carlssonb5133c22009-05-14 21:20:16 +000024 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 *')}}
Anders Carlssonc3a68b22009-05-14 19:52:19 +000025};
26
27}
28
29namespace T3 {
30
31struct a { };
32struct b : private a { }; // expected-note{{'private' inheritance specifier here}}
33
34class A {
35 virtual a* f(); // expected-note{{overridden virtual function is here}}
36};
37
38class B : A {
39 virtual b* f(); // expected-error{{return type of virtual function 'f' is not covariant with the return type of the function it overrides (conversion from 'struct T3::b' to inaccessible base class 'struct T3::a')}}
40};
41
42}
43
44namespace T4 {
45
46struct a { };
47struct a1 : a { };
48struct b : a, a1 { };
49
50class A {
51 virtual a* f(); // expected-note{{overridden virtual function is here}}
52};
53
54class B : A {
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)}}
58};
59
60}
61
62namespace T5 {
63
64struct a { };
65
66class A {
67 virtual a* const f();
68 virtual a* const g(); // expected-note{{overridden virtual function is here}}
69};
70
71class B : A {
72 virtual a* const f();
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')}}
74};
75
76}
77
78namespace T6 {
79
80struct a { };
81
82class A {
83 virtual const a* f();
84 virtual a* g(); // expected-note{{overridden virtual function is here}}
85};
86
87class B : A {
88 virtual a* f();
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 *'}}
90};
91
92}
Anders Carlsson77b7f1d2009-05-14 22:15:41 +000093
94namespace T7 {
95 struct a { };
96 struct b { };
97
98 class A {
99 a* f();
100 };
101
102 class B : A {
103 virtual b* f();
104 };
105}
Douglas Gregord3a50582009-12-01 16:18:00 +0000106
107// PR5656
108class X0 {
109 virtual void f0();
110};
111class X1 : public X0 {
112 void f0() = 0;
113};
Douglas Gregor4ba31362009-12-01 17:24:26 +0000114
115template <typename Base>
116struct Foo : Base {
Douglas Gregore6342c02009-12-01 17:35:23 +0000117 void f(int) = 0; // expected-error{{not virtual and cannot be declared pure}}
Douglas Gregor4ba31362009-12-01 17:24:26 +0000118};
119
Douglas Gregore6342c02009-12-01 17:35:23 +0000120struct Base1 { virtual void f(int); };
Douglas Gregor4ba31362009-12-01 17:24:26 +0000121struct Base2 { };
122
123void test() {
Douglas Gregor1ab537b2009-12-03 18:33:45 +0000124 (void)sizeof(Foo<Base1>);
125 (void)sizeof(Foo<Base2>); // expected-note{{instantiation}}
Douglas Gregor4ba31362009-12-01 17:24:26 +0000126}
Douglas Gregore6342c02009-12-01 17:35:23 +0000127
128template<typename Base>
129struct Foo2 : Base {
130 template<typename T> int f(T);
131};
132
133void test2() {
134 Foo2<Base1> f1;
135 Foo2<Base2> f2;
136 f1.f(17);
137 f2.f(17);
138};
Douglas Gregor1ab537b2009-12-03 18:33:45 +0000139
140struct Foo3 {
141 virtual void f(int) = 0; // expected-note{{pure virtual function}}
142};
143
144template<typename T>
145struct Bar3 : Foo3 {
146 void f(T);
147};
148
149void test3() {
150 Bar3<int> b3i; // okay
151 Bar3<float> b3f; // expected-error{{is an abstract class}}
152}