Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / compilerplugins / clang / test / unnecessaryoverride.cxx
blob7941263e2cec803686fb140a62f6fb277db0627b
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 #if CLANG_VERSION >= 30900 // cf. corresponding condition in Plugin::checkIdenticalDefaultArguments
73 void
74 defaults( // expected-error {{public function just calls public parent [loplugin:unnecessaryoverride]}}
75 void* x1 = 0, int x2 = (1 - 1), double x3 = 1.0, Base const& x4 = (Base()),
76 char const* x5 = "f"
77 "oo")
79 Base::defaults(x1, x2, x3, x4, x5);
81 #endif
84 struct DerivedSlightlyDifferent : Base
86 void defaults( // no warning
87 void* x1 = nullptr, int x2 = 0, double x3 = 1, Base const& x4 = DerivedSlightlyDifferent(),
88 char const* x5 = "foo")
90 Base::defaults(x1, x2, x3, x4, x5);
94 enum class E
96 E1 = 1,
97 E2 = 2,
98 E3 = 4
100 namespace o3tl
102 template <> struct typed_flags<E> : is_typed_flags<E, 7>
107 struct Base2
109 void default1(Base const& = SimpleDerived());
110 void default2(Base const& = SimpleDerived());
111 void default3(Base = Base());
112 void default4(E = (E::E1 | E::E2 | E::E3));
115 struct Derived2 : Base2
117 void default1(Base const& x = Intermediate1()) { Base2::default1(x); } // no warning
118 void
119 default2( // expected-error {{public function just calls public parent [loplugin:unnecessaryoverride]}}
120 Base const& x = SimpleDerived())
122 Base2::default2(x);
124 void
125 default3( // expected-error {{public function just calls public parent [loplugin:unnecessaryoverride]}}
126 Base x = Base())
128 (Base2::default3(x));
130 void
131 default4( // expected-error {{public function just calls public parent [loplugin:unnecessaryoverride]}}
132 E x = (E::E1 | E::E2 | E::E3))
134 Base2::default4(x);
138 class Base3
140 public:
141 void f1();
144 class Derived3 : protected Base3
146 public:
147 // effectively changing access from protected to public
148 void f1() { Base3::f1(); }
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */