blob: 4a3b10fa976461fdde1922bec699423c43ce07b9 [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 +00002
3namespace T1 {
4
5class A {
6 virtual int f(); // expected-note{{overridden virtual function is here}}
7};
8
9class B : A {
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')}}
11};
12
13}
Anders Carlssonc3a68b22009-05-14 19:52:19 +000014
15namespace T2 {
16
17struct a { };
18struct b { };
19
20class A {
21 virtual a* f(); // expected-note{{overridden virtual function is here}}
22};
23
24class B : A {
Anders Carlssonb5133c22009-05-14 21:20:16 +000025 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 +000026};
27
28}
29
30namespace T3 {
31
32struct a { };
33struct b : private a { }; // expected-note{{'private' inheritance specifier here}}
34
35class A {
36 virtual a* f(); // expected-note{{overridden virtual function is here}}
37};
38
39class B : A {
40 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')}}
41};
42
43}
44
45namespace T4 {
46
47struct a { };
48struct a1 : a { };
49struct b : a, a1 { };
50
51class A {
52 virtual a* f(); // expected-note{{overridden virtual function is here}}
53};
54
55class B : A {
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 'struct T4::b' to base class 'struct T4::a':\n\
57 struct T4::b -> struct T4::a\n\
58 struct T4::b -> struct T4::a1 -> struct T4::a)}}
59};
60
61}
62
63namespace T5 {
64
65struct a { };
66
67class A {
68 virtual a* const f();
69 virtual a* const g(); // expected-note{{overridden virtual function is here}}
70};
71
72class B : A {
73 virtual a* const f();
74 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')}}
75};
76
77}
78
79namespace T6 {
80
81struct a { };
82
83class A {
84 virtual const a* f();
85 virtual a* g(); // expected-note{{overridden virtual function is here}}
86};
87
88class B : A {
89 virtual a* f();
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 'struct T6::a const *' is more qualified than class type 'struct T6::a *'}}
91};
92
93}
Anders Carlsson77b7f1d2009-05-14 22:15:41 +000094
95namespace T7 {
96 struct a { };
97 struct b { };
98
99 class A {
100 a* f();
101 };
102
103 class B : A {
104 virtual b* f();
105 };
106}