• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -fsyntax-only -Woverloaded-virtual -verify %s
2 
3 struct B1 {
4   virtual void foo(int); // expected-note {{declared here}}
5   virtual void foo(); // expected-note {{declared here}}
6 };
7 
8 struct S1 : public B1 {
9   void foo(float); // expected-warning {{hides overloaded virtual functions}}
10 };
11 
12 struct S2 : public B1 {
13   void foo(); // expected-note {{declared here}}
14 };
15 
16 struct B2 {
17   virtual void foo(void*); // expected-note {{declared here}}
18 };
19 
20 struct MS1 : public S2, public B2 {
21    virtual void foo(int); // expected-warning {{hides overloaded virtual functions}}
22 };
23 
24 struct B3 {
25   virtual void foo(int);
26   virtual void foo();
27 };
28 
29 struct S3 : public B3 {
30   using B3::foo;
31   void foo(float);
32 };
33 
34 struct B4 {
35   virtual void foo();
36 };
37 
38 struct S4 : public B4 {
39   void foo(float);
40   void foo();
41 };
42 
43 namespace PR9182 {
44 struct Base {
45   virtual void foo(int);
46 };
47 
foo(int)48 void Base::foo(int) { }
49 
50 struct Derived : public Base {
51   virtual void foo(int);
52   void foo(int, int);
53 };
54 }
55 
56 namespace PR9396 {
57 class A {
58 public:
f(int)59   virtual void f(int) {}
60 };
61 
62 class B : public A {
63 public:
f()64   static void f() {}
65 };
66 }
67 
68 namespace ThreeLayer {
69 struct A {
70   virtual void f();
71 };
72 
73 struct B: A {
74   void f();
75   void f(int);
76 };
77 
78 struct C: B {
79   void f(int);
80   using A::f;
81 };
82 }
83 
84 namespace UnbalancedVirtual {
85 struct Base {
86   virtual void func();
87 };
88 
89 struct Derived1: virtual Base {
90   virtual void func();
91 };
92 
93 struct Derived2: virtual Base {
94 };
95 
96 struct MostDerived: Derived1, Derived2 {
97   void func(int);
98   void func();
99 };
100 }
101 
102 namespace UnbalancedVirtual2 {
103 struct Base {
104   virtual void func();
105 };
106 
107 struct Derived1: virtual Base {
108   virtual void func();
109 };
110 
111 struct Derived2: virtual Base {
112 };
113 
114 struct Derived3: Derived1 {
115   virtual void func();
116 };
117 
118 struct MostDerived: Derived3, Derived2 {
119   void func(int);
120   void func();
121 };
122 }
123 
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)}}
134   };
135 
136   class B : public A {
137     virtual int foo(int) const;
138     // expected-warning@-1{{hides overloaded virtual functions}}
139   };
140 }
141 
142 namespace {
143 struct base {
f__anon09ef37340211::base144   void f(char) {}
145 };
146 
147 struct derived : base {
f__anon09ef37340211::derived148   void f(int) {}
149 };
150 
foo(derived & d)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.
157 }
158 }
159