bump product version to 6.3.0.0.beta1
[LibreOffice.git] / compilerplugins / clang / test / unnecessaryoverride.cxx
blobf8c210213922ab1d9c2c24601b22aa5324134f66
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/config.h>
12 #include <config_clang.h>
13 #include <o3tl/typed_flags_set.hxx>
15 struct Base
17 virtual ~Base();
18 virtual void f();
19 void variadic(int, ...);
20 void cv() const volatile;
21 void ref();
22 static void staticFn();
23 void defaults(void* = nullptr, int = 0, double = 1, Base const& = {}, char const* = "foo");
26 struct SimpleDerived : Base
28 void
29 f() override // expected-error {{public virtual function just calls public parent [loplugin:unnecessaryoverride]}}
31 Base::f();
35 struct Intermediate1 : Base
39 struct MultiFunctionIntermediate2 : Base
41 void f() override;
44 struct MultiFunctionDerived : Intermediate1, MultiFunctionIntermediate2
46 void f() override { Intermediate1::f(); } // no warning
49 struct MultiClassIntermediate2 : Base
53 struct MultiClassDerived : Intermediate1, MultiClassIntermediate2
55 void f() override { Intermediate1::f(); } // no warning
58 struct DerivedDifferent : Base
60 void variadic(int x) { Base::variadic(x); } // no warning
61 void cv() { Base::cv(); } // no warning
62 void ref() && { Base::ref(); } // no warning
63 void staticFn() { Base::staticFn(); } // no warning
64 void defaults(void* x1, int x2, double x3, Base const& x4, char const* x5)
66 Base::defaults(x1, x2, x3, x4, x5); // no warning
70 struct DerivedSame : Base
72 void
73 defaults( // expected-error {{public function just calls public parent [loplugin:unnecessaryoverride]}}
74 void* x1 = 0, int x2 = (1 - 1), double x3 = 1.0, Base const& x4 = (Base()),
75 char const* x5 = "f"
76 "oo")
78 Base::defaults(x1, x2, x3, x4, x5);
82 struct DerivedSlightlyDifferent : Base
84 void defaults( // no warning
85 void* x1 = nullptr, int x2 = 0, double x3 = 1, Base const& x4 = DerivedSlightlyDifferent(),
86 char const* x5 = "foo")
88 Base::defaults(x1, x2, x3, x4, x5);
92 enum class E
94 E1 = 1,
95 E2 = 2,
96 E3 = 4
98 namespace o3tl
100 template <> struct typed_flags<E> : is_typed_flags<E, 7>
105 struct Base2
107 void default1(Base const& = SimpleDerived());
108 void default2(Base const& = SimpleDerived());
109 void default3(Base = Base());
110 void default4(E = (E::E1 | E::E2 | E::E3));
113 struct Derived2 : Base2
115 void default1(Base const& x = Intermediate1()) { Base2::default1(x); } // no warning
116 void
117 default2( // expected-error {{public function just calls public parent [loplugin:unnecessaryoverride]}}
118 Base const& x = SimpleDerived())
120 Base2::default2(x);
122 void
123 default3( // expected-error {{public function just calls public parent [loplugin:unnecessaryoverride]}}
124 Base x = Base())
126 (Base2::default3(x));
128 void
129 default4( // expected-error {{public function just calls public parent [loplugin:unnecessaryoverride]}}
130 E x = (E::E1 | E::E2 | E::E3))
132 Base2::default4(x);
136 class Base3
138 public:
139 void f1();
142 class Derived3 : protected Base3
144 public:
145 // effectively changing access from protected to public
146 void f1() { Base3::f1(); }
149 // check the case where the method occurs more than once in a direct path up the class hierarchy
150 struct Base4
152 void f1();
154 struct Derived4_1 : public Base4
156 void f1();
158 struct Derived4_2 : public Derived4_1
160 void
161 f1() // expected-error {{public function just calls public parent [loplugin:unnecessaryoverride]}}
163 Derived4_1::f1();
167 struct Base5_1
169 void f1();
171 struct Base5_2
173 void f1();
175 struct Derived5 : public Base5_1, public Base5_2
177 void f1() { Base5_1::f1(); } // no warning expected
180 struct Base6_1
182 bool f1();
184 struct Derived6 : public Base6_1
186 bool
187 f1() // expected-error {{public function just calls public parent [loplugin:unnecessaryoverride]}}
189 bool ret = Base6_1::f1();
190 return ret;
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */