From af908d9f18fbb83a5c393f856026cebefd821f18 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 15 Oct 2021 10:33:07 +0200 Subject: 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' 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::disjunction>, std::_Has_no_alloc_destroy, 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::disjunction>, std::_Has_no_alloc_destroy, Primitive *>>>' requested here > if constexpr (!conjunction_v, _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>' 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::_Tidy' requested here > _Tidy(); > ^ > C:/lo-clang/core/slideshow/source/engine/opengl/TransitionImpl.hxx(74,5): note: in instantiation of member function 'std::vector::~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 --- compilerplugins/clang/test/unnecessaryoverride-dtor.cxx | 4 ++-- compilerplugins/clang/unnecessaryoverride.cxx | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/test/unnecessaryoverride-dtor.cxx b/compilerplugins/clang/test/unnecessaryoverride-dtor.cxx index b54957be2d7a..8ed472749105 100644 --- a/compilerplugins/clang/test/unnecessaryoverride-dtor.cxx +++ b/compilerplugins/clang/test/unnecessaryoverride-dtor.cxx @@ -78,10 +78,10 @@ struct DefaultDerived1: VirtualBase { }; struct DefaultDerived2: VirtualBase { - ~DefaultDerived2() override; // expected-note {{declared here [loplugin:unnecessaryoverride]}} + ~DefaultDerived2() override; }; -DefaultDerived2::~DefaultDerived2() = default; // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}} +DefaultDerived2::~DefaultDerived2() = default; struct EmptyDerived1: VirtualBase { ~EmptyDerived1() override {}; // expected-error {{unnecessary user-declared destructor [loplugin:unnecessaryoverride]}} diff --git a/compilerplugins/clang/unnecessaryoverride.cxx b/compilerplugins/clang/unnecessaryoverride.cxx index 6523170105a2..0641339d4e6f 100644 --- a/compilerplugins/clang/unnecessaryoverride.cxx +++ b/compilerplugins/clang/unnecessaryoverride.cxx @@ -200,7 +200,11 @@ bool UnnecessaryOverride::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl) { return true; } - if (!methodDecl->isExplicitlyDefaulted()) { + if (methodDecl->isExplicitlyDefaulted()) { + if (methodDecl->getPreviousDecl() != nullptr) { + return true; + } + } else { if (!methodDecl->doesThisDeclarationHaveABody() || methodDecl->isLateTemplateParsed()) { -- cgit