Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / compilerplugins / clang / test / unnecessaryoverride-dtor.cxx
blobb54957be2d7acd46cb4e502f0695e784b7e76df8
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 <salhelper/simplereferenceobject.hxx>
14 #include "unnecessaryoverride-dtor.hxx"
16 struct NonVirtualBase {};
18 struct NonVirtualDerived1: NonVirtualBase {
19 ~NonVirtualDerived1() {} // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
22 struct NonVirtualDerived2: NonVirtualBase {
23 virtual ~NonVirtualDerived2() {}
26 struct PrivateDerived: VirtualBase {
27 private:
28 ~PrivateDerived() override {}
31 struct ProtectedDerived: VirtualBase {
32 protected:
33 ~ProtectedDerived() override {}
36 IncludedDerived2::~IncludedDerived2() {}
38 struct Incomplete: salhelper::SimpleReferenceObject {};
40 IncludedDerived3::IncludedDerived3() {}
42 IncludedDerived3::~IncludedDerived3() {}
44 // vmiklos likes these because he can quickly add a DEBUG or something similar without
45 // massive recompile
46 IncludedNotDerived::~IncludedNotDerived() {}
48 struct NoExSpecDerived: VirtualBase {
49 ~NoExSpecDerived() override {} // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
52 struct NoThrowDerived: VirtualBase {
53 ~NoThrowDerived() throw () override {} // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
56 struct NoexceptDerived: VirtualBase {
57 ~NoexceptDerived() noexcept override {} // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
60 struct NoexceptTrueDerived: VirtualBase {
61 ~NoexceptTrueDerived() noexcept(true) override {} // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
64 #if 0
65 struct NoexceptFalseBase {
66 virtual ~NoexceptFalseBase() noexcept(false) {}
69 struct NoexceptFalseDerived: NoexceptFalseBase {
70 ~NoexceptFalseDerived() noexcept(false) override {}
72 #endif
74 struct NoDtorDerived: VirtualBase {};
76 struct DefaultDerived1: VirtualBase {
77 ~DefaultDerived1() override = default; // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
80 struct DefaultDerived2: VirtualBase {
81 ~DefaultDerived2() override; // expected-note {{declared here [loplugin:unnecessaryoverride]}}
84 DefaultDerived2::~DefaultDerived2() = default; // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
86 struct EmptyDerived1: VirtualBase {
87 ~EmptyDerived1() override {}; // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
90 struct EmptyDerived2: VirtualBase {
91 ~EmptyDerived2() override; // expected-note {{declared here [loplugin:unnecessaryoverride]}}
94 EmptyDerived2::~EmptyDerived2() {} // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
96 struct NonEmptyDerived: VirtualBase {
97 ~NonEmptyDerived() override { (void) 0; }
100 struct CatchDerived: VirtualBase {
101 ~CatchDerived() override try {} catch (...) {}
104 struct DeleteBase {
105 virtual ~DeleteBase() = delete;
108 struct DeleteDerived: DeleteBase {
109 ~DeleteDerived() override = delete;
112 struct PureBase {
113 virtual ~PureBase() = 0;
116 struct PureDerived: PureBase {
117 ~PureDerived() override {} // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
120 struct CompleteBase {
121 ~CompleteBase() {} // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
124 // <sberg> noelgrandin, there's one other corner case one can imagine:
125 // a class defined in a .hxx with the dtor declared (but not defined) as inline in the .hxx,
126 // and then defined in the cxx (making it effectively only callable from within the cxx);
127 // removing the dtor declaration from the class definition would change the dtor to be callable from everywhere
128 MarkedInlineButNotDefined::~MarkedInlineButNotDefined() {}
130 // avoid loplugin:unreffun:
131 int main() {
132 (void) NonVirtualDerived1();
133 (void) DefaultDerived1();
134 (void) CompleteBase();
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */