Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / compilerplugins / clang / test / unnecessaryoverride.cxx
blobbf1e61352315d267b2a62ca17027b8eda41dc14b
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 Base();
18 Base(Base const&);
19 virtual ~Base();
20 Base& operator=(Base const&);
21 virtual void f();
22 void variadic(int, ...);
23 void cv() const volatile;
24 void ref();
25 static void staticFn();
26 void defaults(void* = nullptr, int = 0, double = 1, Base const& = {}, char const* = "foo");
29 struct SimpleDerived : Base
31 void
32 f() override // expected-error {{public virtual function just calls public parent [loplugin:unnecessaryoverride]}}
34 Base::f();
38 struct Intermediate1 : Base
42 struct MultiFunctionIntermediate2 : Base
44 void f() override;
47 struct MultiFunctionDerived : Intermediate1, MultiFunctionIntermediate2
49 void f() override { Intermediate1::f(); } // no warning
52 struct MultiClassIntermediate2 : Base
56 struct MultiClassDerived : Intermediate1, MultiClassIntermediate2
58 void f() override { Intermediate1::f(); } // no warning
61 struct DerivedDifferent : Base
63 void variadic(int x) { Base::variadic(x); } // no warning
64 void cv() { Base::cv(); } // no warning
65 void ref() && { Base::ref(); } // no warning
66 void staticFn() { Base::staticFn(); } // no warning
67 void defaults(void* x1, int x2, double x3, Base const& x4, char const* x5)
69 Base::defaults(x1, x2, x3, x4, x5); // no warning
73 struct DerivedSame : Base
75 void
76 defaults( // expected-error {{public function just calls public parent [loplugin:unnecessaryoverride]}}
77 void* x1 = 0, int x2 = (1 - 1), double x3 = 1.0, Base const& x4 = (Base()),
78 char const* x5 = "f"
79 "oo")
81 Base::defaults(x1, x2, x3, x4, x5);
85 struct DerivedSlightlyDifferent : Base
87 void defaults( // no warning
88 void* x1 = nullptr, int x2 = 0, double x3 = 1, Base const& x4 = DerivedSlightlyDifferent(),
89 char const* x5 = "foo")
91 Base::defaults(x1, x2, x3, x4, x5);
95 enum class E
97 E1 = 1,
98 E2 = 2,
99 E3 = 4
101 namespace o3tl
103 template <> struct typed_flags<E> : is_typed_flags<E, 7>
108 struct Base2
110 void default1(Base const& = SimpleDerived());
111 void default2(Base const& = SimpleDerived());
112 void default3(Base = Base());
113 void default4(E = (E::E1 | E::E2 | E::E3));
116 struct Derived2 : Base2
118 void default1(Base const& x = Intermediate1()) { Base2::default1(x); } // no warning
119 void
120 default2( // expected-error {{public function just calls public parent [loplugin:unnecessaryoverride]}}
121 Base const& x = SimpleDerived())
123 Base2::default2(x);
125 void
126 default3( // expected-error {{public function just calls public parent [loplugin:unnecessaryoverride]}}
127 Base x = Base())
129 (Base2::default3(x));
131 void
132 default4( // expected-error {{public function just calls public parent [loplugin:unnecessaryoverride]}}
133 E x = (E::E1 | E::E2 | E::E3))
135 Base2::default4(x);
139 class Base3
141 public:
142 void f1();
145 class Derived3 : protected Base3
147 public:
148 // effectively changing access from protected to public
149 void f1() { Base3::f1(); }
152 // check the case where the method occurs more than once in a direct path up the class hierarchy
153 struct Base4
155 void f1();
157 struct Derived4_1 : public Base4
159 void f1();
161 struct Derived4_2 : public Derived4_1
163 void
164 f1() // expected-error {{public function just calls public parent [loplugin:unnecessaryoverride]}}
166 Derived4_1::f1();
170 struct Base5_1
172 void f1();
174 struct Base5_2
176 void f1();
178 struct Derived5 : public Base5_1, public Base5_2
180 void f1() { Base5_1::f1(); } // no warning expected
183 struct Base6_1
185 bool f1();
187 struct Derived6 : public Base6_1
189 bool
190 f1() // expected-error {{public function just calls public parent [loplugin:unnecessaryoverride]}}
192 bool ret = Base6_1::f1();
193 return ret;
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */