blob: 6204826192d7b24747b3d6fe990156254645ea9a [file] [log] [blame]
Argyrios Kyrtzidis799ef662011-02-03 18:01:15 +00001// RUN: %clang_cc1 -fsyntax-only -Woverloaded-virtual -verify %s
2
3struct B1 {
4 virtual void foo(int); // expected-note {{declared here}}
5 virtual void foo(); // expected-note {{declared here}}
6};
7
8struct S1 : public B1 {
9 void foo(float); // expected-warning {{hides overloaded virtual functions}}
10};
11
12struct S2 : public B1 {
13 void foo(); // expected-note {{declared here}}
14};
15
16struct B2 {
17 virtual void foo(void*); // expected-note {{declared here}}
18};
19
20struct MS1 : public S2, public B2 {
21 virtual void foo(int); // expected-warning {{hides overloaded virtual functions}}
22};
23
24struct B3 {
25 virtual void foo(int);
26 virtual void foo();
27};
28
29struct S3 : public B3 {
30 using B3::foo;
31 void foo(float);
32};
33
34struct B4 {
35 virtual void foo();
36};
37
38struct S4 : public B4 {
39 void foo(float);
40 void foo();
41};
Argyrios Kyrtzidis74b47f92011-02-10 18:13:41 +000042
43namespace PR9182 {
44struct Base {
45 virtual void foo(int);
46};
47
48void Base::foo(int) { }
49
50struct Derived : public Base {
Stephen Hines176edba2014-12-01 14:53:08 -080051 virtual void foo(int);
52 void foo(int, int);
Argyrios Kyrtzidis74b47f92011-02-10 18:13:41 +000053};
54}
Argyrios Kyrtzidis0266aa32011-03-03 22:58:57 +000055
56namespace PR9396 {
57class A {
58public:
59 virtual void f(int) {}
60};
61
62class B : public A {
63public:
64 static void f() {}
65};
66}
David Blaikie76398e52012-10-17 23:45:39 +000067
68namespace ThreeLayer {
69struct A {
70 virtual void f();
71};
72
73struct B: A {
74 void f();
75 void f(int);
76};
77
78struct C: B {
79 void f(int);
80 using A::f;
81};
82}
David Blaikie5f750682012-10-19 00:53:08 +000083
84namespace UnbalancedVirtual {
85struct Base {
86 virtual void func();
87};
88
89struct Derived1: virtual Base {
90 virtual void func();
91};
92
93struct Derived2: virtual Base {
94};
95
96struct MostDerived: Derived1, Derived2 {
97 void func(int);
98 void func();
99};
100}
101
102namespace UnbalancedVirtual2 {
103struct Base {
104 virtual void func();
105};
106
107struct Derived1: virtual Base {
108 virtual void func();
109};
110
111struct Derived2: virtual Base {
112};
113
114struct Derived3: Derived1 {
115 virtual void func();
116};
117
118struct MostDerived: Derived3, Derived2 {
119 void func(int);
120 void func();
121};
122}
Richard Trieuf608aff2013-04-05 23:02:24 +0000123
124namespace {
125 class A {
126 virtual int foo(bool) const;
127 // expected-note@-1{{type mismatch at 1st parameter ('bool' vs 'int')}}
128 virtual int foo(int, int) const;
129 // expected-note@-1{{different number of parameters (2 vs 1)}}
130 virtual int foo(int*) const;
131 // expected-note@-1{{type mismatch at 1st parameter ('int *' vs 'int')}}
132 virtual int foo(int) volatile;
133 // expected-note@-1{{different qualifiers (volatile vs const)}}
134 };
135
136 class B : public A {
137 virtual int foo(int) const;
138 // expected-warning@-1{{hides overloaded virtual functions}}
139 };
140}
Stephen Hines176edba2014-12-01 14:53:08 -0800141
142namespace {
143struct base {
144 void f(char) {}
145};
146
147struct derived : base {
148 void f(int) {}
149};
150
151void foo(derived &d) {
152 d.f('1'); // FIXME: this should warn about calling (anonymous namespace)::derived::f(int)
153 // instead of (anonymous namespace)::base::f(char).
154 // Note: this should be under a new diagnostic flag and eventually moved to a
155 // new test case since it's not strictly related to virtual functions.
156 d.f(12); // This should not warn.
157}
158}