[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaCXX / warn-overloaded-virtual.cpp
blob271416d04d55de88475818c42a076b63ef60b4dc
1 // RUN: %clang_cc1 -fsyntax-only -Woverloaded-virtual -verify %s
3 struct B1 {
4 virtual void foo(int); // expected-note {{declared here}}
5 virtual void foo(); // expected-note {{declared here}}
6 };
8 struct S1 : public B1 {
9 void foo(float); // expected-warning {{hides overloaded virtual functions}}
12 struct S2 : public B1 {
13 void foo(); // expected-note {{declared here}}
16 struct B2 {
17 virtual void foo(void*); // expected-note {{declared here}}
20 struct MS1 : public S2, public B2 {
21 virtual void foo(int); // expected-warning {{hides overloaded virtual functions}}
24 struct B3 {
25 virtual void foo(int);
26 virtual void foo();
29 struct S3 : public B3 {
30 using B3::foo;
31 void foo(float);
34 struct B4 {
35 virtual void foo();
38 struct S4 : public B4 {
39 void foo(float);
40 void foo();
43 namespace PR9182 {
44 struct Base {
45 virtual void foo(int);
48 void Base::foo(int) { }
50 struct Derived : public Base {
51 virtual void foo(int);
52 void foo(int, int);
56 namespace PR9396 {
57 class A {
58 public:
59 virtual void f(int) {}
62 class B : public A {
63 public:
64 static void f() {}
68 namespace ThreeLayer {
69 struct A {
70 virtual void f();
73 struct B: A {
74 void f();
75 void f(int);
78 struct C: B {
79 void f(int);
80 using A::f;
84 namespace UnbalancedVirtual {
85 struct Base {
86 virtual void func();
89 struct Derived1: virtual Base {
90 virtual void func();
93 struct Derived2: virtual Base {
96 struct MostDerived: Derived1, Derived2 {
97 void func(int);
98 void func();
102 namespace UnbalancedVirtual2 {
103 struct Base {
104 virtual void func();
107 struct Derived1: virtual Base {
108 virtual void func();
111 struct Derived2: virtual Base {
114 struct Derived3: Derived1 {
115 virtual void func();
118 struct MostDerived: Derived3, Derived2 {
119 void func(int);
120 void func();
124 namespace {
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')}}
136 class B : public A {
137 virtual int foo(int) const;
138 // expected-warning@-1{{hides overloaded virtual functions}}
142 namespace {
143 struct base {
144 void f(char) {}
147 struct derived : base {
148 void f(int) {}
151 void 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.