]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/SemaCXX/virtual-override.cpp
Update clang to r86025.
[FreeBSD/FreeBSD.git] / test / SemaCXX / virtual-override.cpp
1 // RUN: clang-cc -fsyntax-only -faccess-control -verify %s
2
3 namespace T1 {
4
5 class A {
6   virtual int f(); // expected-note{{overridden virtual function is here}}
7 };
8
9 class 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 }
14
15 namespace T2 {
16
17 struct a { };
18 struct b { };
19   
20 class A {
21   virtual a* f(); // expected-note{{overridden virtual function is here}}
22 };
23
24 class B : A {
25   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 *')}}
26 };
27
28 }
29
30 namespace T3 {
31
32 struct a { };
33 struct b : private a { }; // expected-note{{'private' inheritance specifier here}}
34   
35 class A {
36   virtual a* f(); // expected-note{{overridden virtual function is here}}
37 };
38
39 class 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
45 namespace T4 {
46
47 struct a { };
48 struct a1 : a { };
49 struct b : a, a1 { };
50   
51 class A {
52   virtual a* f(); // expected-note{{overridden virtual function is here}}
53 };
54
55 class 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
63 namespace T5 {
64   
65 struct a { };
66
67 class A {
68   virtual a* const f(); 
69   virtual a* const g(); // expected-note{{overridden virtual function is here}}
70 };
71
72 class 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
79 namespace T6 {
80   
81 struct a { };
82
83 class A {
84   virtual const a* f(); 
85   virtual a* g(); // expected-note{{overridden virtual function is here}}
86 };
87
88 class 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 }
94
95 namespace 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 }