2016-12-05 09:06:14 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sal/config.h>
|
|
|
|
|
|
|
|
#include <salhelper/simplereferenceobject.hxx>
|
|
|
|
|
2017-11-01 18:16:40 +01:00
|
|
|
#include "unnecessaryoverride-dtor.hxx"
|
2016-12-05 09:06:14 +01:00
|
|
|
|
|
|
|
struct NonVirtualBase {};
|
|
|
|
|
|
|
|
struct NonVirtualDerived1: NonVirtualBase {
|
2017-01-12 16:27:14 +02:00
|
|
|
~NonVirtualDerived1() {} // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
|
2016-12-05 09:06:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NonVirtualDerived2: NonVirtualBase {
|
|
|
|
virtual ~NonVirtualDerived2() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PrivateDerived: VirtualBase {
|
|
|
|
private:
|
|
|
|
~PrivateDerived() override {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ProtectedDerived: VirtualBase {
|
|
|
|
protected:
|
|
|
|
~ProtectedDerived() override {}
|
|
|
|
};
|
|
|
|
|
|
|
|
IncludedDerived2::~IncludedDerived2() {}
|
|
|
|
|
|
|
|
struct Incomplete: salhelper::SimpleReferenceObject {};
|
|
|
|
|
|
|
|
IncludedDerived3::IncludedDerived3() {}
|
|
|
|
|
|
|
|
IncludedDerived3::~IncludedDerived3() {}
|
|
|
|
|
2017-01-12 16:27:14 +02:00
|
|
|
// vmiklos likes these because he can quickly add a DEBUG or something similar without
|
|
|
|
// massive recompile
|
|
|
|
IncludedNotDerived::~IncludedNotDerived() {}
|
|
|
|
|
2016-12-05 09:06:14 +01:00
|
|
|
struct NoExSpecDerived: VirtualBase {
|
|
|
|
~NoExSpecDerived() override {} // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NoThrowDerived: VirtualBase {
|
|
|
|
~NoThrowDerived() throw () override {} // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NoexceptDerived: VirtualBase {
|
|
|
|
~NoexceptDerived() noexcept override {} // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NoexceptTrueDerived: VirtualBase {
|
|
|
|
~NoexceptTrueDerived() noexcept(true) override {} // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
|
|
|
|
};
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
struct NoexceptFalseBase {
|
|
|
|
virtual ~NoexceptFalseBase() noexcept(false) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NoexceptFalseDerived: NoexceptFalseBase {
|
|
|
|
~NoexceptFalseDerived() noexcept(false) override {}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct NoDtorDerived: VirtualBase {};
|
|
|
|
|
|
|
|
struct DefaultDerived1: VirtualBase {
|
|
|
|
~DefaultDerived1() override = default; // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DefaultDerived2: VirtualBase {
|
Avoid usage of incomplete types in member functions defined in-class
...that started to fail now at least with clang-cl (where the MSVC rules when to
emit inline member function definitions are more aggressive than for other ABIs)
with --with-latest-c++ and --with-visual-studio=2022 (where usage of incomplete
types in std::vector now triggered
> In file included from C:/lo-clang/core/slideshow/source/engine/opengl/TransitionerImpl.cxx:31:
> In file included from C:/PROGRA~1/MIB055~1/2022/Preview/VC/Tools/MSVC/1430~1.305/Include\memory:11:
> In file included from C:/PROGRA~1/MIB055~1/2022/Preview/VC/Tools/MSVC/1430~1.305/Include\exception:12:
> C:/PROGRA~1/MIB055~1/2022/Preview/VC/Tools/MSVC/1430~1.305/Include\type_traits(744,50): error: incomplete type 'Primitive' used in type trait expression
> struct is_trivially_destructible : bool_constant<__is_trivially_destructible(_Ty)> {
> ^
> C:/PROGRA~1/MIB055~1/2022/Preview/VC/Tools/MSVC/1430~1.305/Include\type_traits(59,53): note: in instantiation of template class 'std::is_trivially_destructible<Primitive>' requested here
> struct conjunction<_First, _Rest...> : _Conjunction<_First::value, _First, _Rest...>::type {
> ^
> C:/PROGRA~1/MIB055~1/2022/Preview/VC/Tools/MSVC/1430~1.305/Include\type_traits(64,44): note: in instantiation of template class 'std::conjunction<std::is_trivially_destructible<Primitive>, std::disjunction<std::_Is_default_allocator<std::allocator<Primitive>>, std::_Has_no_alloc_destroy<std::allocator<Primitive>, Primitive *>>>' requested here
> _INLINE_VAR constexpr bool conjunction_v = conjunction<_Traits...>::value;
> ^
> C:/PROGRA~1/MIB055~1/2022/Preview/VC/Tools/MSVC/1430~1.305/Include\xmemory(934,20): note: in instantiation of variable template specialization 'std::conjunction_v<std::is_trivially_destructible<Primitive>, std::disjunction<std::_Is_default_allocator<std::allocator<Primitive>>, std::_Has_no_alloc_destroy<std::allocator<Primitive>, Primitive *>>>' requested here
> if constexpr (!conjunction_v<is_trivially_destructible<_Ty>, _Uses_default_destroy<_Alloc, _Ty*>>) {
> ^
> C:/PROGRA~1/MIB055~1/2022/Preview/VC/Tools/MSVC/1430~1.305/Include\vector(1632,13): note: in instantiation of function template specialization 'std::_Destroy_range<std::allocator<Primitive>>' requested here
> _Destroy_range(_Myfirst, _Mylast, _Al);
> ^
> C:/PROGRA~1/MIB055~1/2022/Preview/VC/Tools/MSVC/1430~1.305/Include\vector(583,9): note: in instantiation of member function 'std::vector<Primitive>::_Tidy' requested here
> _Tidy();
> ^
> C:/lo-clang/core/slideshow/source/engine/opengl/TransitionImpl.hxx(74,5): note: in instantiation of member function 'std::vector<Primitive>::~vector' requested here
> TransitionScene(
> ^
> C:/lo-clang/core/slideshow/source/engine/opengl/TransitionImpl.hxx(42,7): note: forward declaration of 'Primitive'
> class Primitive;
> ^
etc.).
Which in turn required tweaking of loplugin:unnecessaryoverride to avoid false
> In file included from C:/lo-clang/core/slideshow/source/engine/opengl/TransitionerImpl.cxx:67:
> C:/lo-clang/core/slideshow/source/engine/opengl/TransitionImpl.hxx(389,18): error: unnecessary user-declared destructor [loplugin:unnecessaryoverride]
> TransitionScene::~TransitionScene() = default;
> ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
> C:/lo-clang/core/slideshow/source/engine/opengl/TransitionImpl.hxx(81,12): note: declared here [loplugin:unnecessaryoverride]
> inline ~TransitionScene();
> ~~~~~~~^~~~~~~~~~~~~~~~~~
Change-Id: Ia72fb44e6e92ff47376d7b7159c0df7cbf883b69
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123648
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2021-10-15 10:33:07 +02:00
|
|
|
~DefaultDerived2() override;
|
2016-12-05 09:06:14 +01:00
|
|
|
};
|
|
|
|
|
Avoid usage of incomplete types in member functions defined in-class
...that started to fail now at least with clang-cl (where the MSVC rules when to
emit inline member function definitions are more aggressive than for other ABIs)
with --with-latest-c++ and --with-visual-studio=2022 (where usage of incomplete
types in std::vector now triggered
> In file included from C:/lo-clang/core/slideshow/source/engine/opengl/TransitionerImpl.cxx:31:
> In file included from C:/PROGRA~1/MIB055~1/2022/Preview/VC/Tools/MSVC/1430~1.305/Include\memory:11:
> In file included from C:/PROGRA~1/MIB055~1/2022/Preview/VC/Tools/MSVC/1430~1.305/Include\exception:12:
> C:/PROGRA~1/MIB055~1/2022/Preview/VC/Tools/MSVC/1430~1.305/Include\type_traits(744,50): error: incomplete type 'Primitive' used in type trait expression
> struct is_trivially_destructible : bool_constant<__is_trivially_destructible(_Ty)> {
> ^
> C:/PROGRA~1/MIB055~1/2022/Preview/VC/Tools/MSVC/1430~1.305/Include\type_traits(59,53): note: in instantiation of template class 'std::is_trivially_destructible<Primitive>' requested here
> struct conjunction<_First, _Rest...> : _Conjunction<_First::value, _First, _Rest...>::type {
> ^
> C:/PROGRA~1/MIB055~1/2022/Preview/VC/Tools/MSVC/1430~1.305/Include\type_traits(64,44): note: in instantiation of template class 'std::conjunction<std::is_trivially_destructible<Primitive>, std::disjunction<std::_Is_default_allocator<std::allocator<Primitive>>, std::_Has_no_alloc_destroy<std::allocator<Primitive>, Primitive *>>>' requested here
> _INLINE_VAR constexpr bool conjunction_v = conjunction<_Traits...>::value;
> ^
> C:/PROGRA~1/MIB055~1/2022/Preview/VC/Tools/MSVC/1430~1.305/Include\xmemory(934,20): note: in instantiation of variable template specialization 'std::conjunction_v<std::is_trivially_destructible<Primitive>, std::disjunction<std::_Is_default_allocator<std::allocator<Primitive>>, std::_Has_no_alloc_destroy<std::allocator<Primitive>, Primitive *>>>' requested here
> if constexpr (!conjunction_v<is_trivially_destructible<_Ty>, _Uses_default_destroy<_Alloc, _Ty*>>) {
> ^
> C:/PROGRA~1/MIB055~1/2022/Preview/VC/Tools/MSVC/1430~1.305/Include\vector(1632,13): note: in instantiation of function template specialization 'std::_Destroy_range<std::allocator<Primitive>>' requested here
> _Destroy_range(_Myfirst, _Mylast, _Al);
> ^
> C:/PROGRA~1/MIB055~1/2022/Preview/VC/Tools/MSVC/1430~1.305/Include\vector(583,9): note: in instantiation of member function 'std::vector<Primitive>::_Tidy' requested here
> _Tidy();
> ^
> C:/lo-clang/core/slideshow/source/engine/opengl/TransitionImpl.hxx(74,5): note: in instantiation of member function 'std::vector<Primitive>::~vector' requested here
> TransitionScene(
> ^
> C:/lo-clang/core/slideshow/source/engine/opengl/TransitionImpl.hxx(42,7): note: forward declaration of 'Primitive'
> class Primitive;
> ^
etc.).
Which in turn required tweaking of loplugin:unnecessaryoverride to avoid false
> In file included from C:/lo-clang/core/slideshow/source/engine/opengl/TransitionerImpl.cxx:67:
> C:/lo-clang/core/slideshow/source/engine/opengl/TransitionImpl.hxx(389,18): error: unnecessary user-declared destructor [loplugin:unnecessaryoverride]
> TransitionScene::~TransitionScene() = default;
> ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
> C:/lo-clang/core/slideshow/source/engine/opengl/TransitionImpl.hxx(81,12): note: declared here [loplugin:unnecessaryoverride]
> inline ~TransitionScene();
> ~~~~~~~^~~~~~~~~~~~~~~~~~
Change-Id: Ia72fb44e6e92ff47376d7b7159c0df7cbf883b69
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123648
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2021-10-15 10:33:07 +02:00
|
|
|
DefaultDerived2::~DefaultDerived2() = default;
|
2016-12-05 09:06:14 +01:00
|
|
|
|
|
|
|
struct EmptyDerived1: VirtualBase {
|
|
|
|
~EmptyDerived1() override {}; // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EmptyDerived2: VirtualBase {
|
|
|
|
~EmptyDerived2() override; // expected-note {{declared here [loplugin:unnecessaryoverride]}}
|
|
|
|
};
|
|
|
|
|
|
|
|
EmptyDerived2::~EmptyDerived2() {} // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
|
|
|
|
|
|
|
|
struct NonEmptyDerived: VirtualBase {
|
|
|
|
~NonEmptyDerived() override { (void) 0; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CatchDerived: VirtualBase {
|
|
|
|
~CatchDerived() override try {} catch (...) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DeleteBase {
|
|
|
|
virtual ~DeleteBase() = delete;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DeleteDerived: DeleteBase {
|
|
|
|
~DeleteDerived() override = delete;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PureBase {
|
|
|
|
virtual ~PureBase() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PureDerived: PureBase {
|
|
|
|
~PureDerived() override {} // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
|
|
|
|
};
|
|
|
|
|
2017-01-12 16:27:14 +02:00
|
|
|
struct CompleteBase {
|
|
|
|
~CompleteBase() {} // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}}
|
|
|
|
};
|
|
|
|
|
|
|
|
// <sberg> noelgrandin, there's one other corner case one can imagine:
|
|
|
|
// a class defined in a .hxx with the dtor declared (but not defined) as inline in the .hxx,
|
|
|
|
// and then defined in the cxx (making it effectively only callable from within the cxx);
|
|
|
|
// removing the dtor declaration from the class definition would change the dtor to be callable from everywhere
|
2021-10-15 15:01:00 +02:00
|
|
|
MarkedInlineButNotDefined::~MarkedInlineButNotDefined() = default;
|
2017-01-12 16:27:14 +02:00
|
|
|
|
|
|
|
// avoid loplugin:unreffun:
|
2016-12-05 09:06:14 +01:00
|
|
|
int main() {
|
|
|
|
(void) NonVirtualDerived1();
|
2017-06-06 08:04:06 +02:00
|
|
|
(void) DefaultDerived1();
|
2017-01-12 16:27:14 +02:00
|
|
|
(void) CompleteBase();
|
2016-12-05 09:06:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|