diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2022-02-12 17:10:43 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2022-02-12 19:37:43 +0100 |
commit | d2ba5d98ec67e684c819ef80421eb496723a8d06 (patch) | |
tree | 050bcf0179c152892a6d4b8e841f71cfe541bef7 /solenv | |
parent | 7cd3013a3704b8365e295f4260e242273d45d27e (diff) |
Fix some tautological std::type_info (in-)equality comparisons
...which could never succeed.
I became aware of this when Clang 15 trunk -std=c++2b, implementing
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p1328r1.html> "Making
std::type_info::operator== constexpr", pointed at two of the broken comparisons
with
> sw/source/uibase/app/docsh2.cxx:478:25: error: code will never be executed [-Werror,-Wunreachable-code]
> pTmpFrame->GetFrame().Appear();
> ^~~~~~~~~
> sw/source/uibase/app/docsh2.cxx:475:33: error: code will never be executed [-Werror,-Wunreachable-code]
> bOnly = false;
> ^~~~~
(It didn't emit warnings pointing at any of the other broken comparisons,
though.)
All of these broken comparisons were regressions introduced with
89d39bc100aabf5dccbe77c0b5c0c85736e85b39 "tdf#94559: 4th step to remove
rtti.hxx", replacing uses of the IS_TYPE macro (from include/tools/rtti.hxx,
meanwhile removed with d64e535fe9a00b671cf1be3eb5632c0d5f4b8bea "Remove unused
rtti.hxx").
I now added loplugin:typeidcomparison to also find the other broken comparisons
introduced by that commit. (The remaining cases where that commit replaced uses
of TYPE_INFO with typeid comparisons were correct and/or have meanwhile been
replaced with code not using typeid, see
553ee72041d6f66e26156eb1ad0d9e3c13457f7a "simplify some use of typeid" and
d656da9bc4f2df0bb99c65a288847e3fdd43a37c "~SwModify: do not silently tolerate
clients registered past death".)
The original IS_TYPE macro made sure not to dereference null pointers,
> #define IS_TYPE(T,pObj) \
> ( pObj && (pObj)->Type() == TYPE(T) )
I don't know if any of the pointers now dereferenced in those typeid expressions
can legitimately be null. But to be on the safe side, I replicated that check
in the newly introduced isType (sw/inc/istype.hxx).
(It is interesting to note that none of the static analysis that we routinely
employ seems to have noticed these broken comparisons.)
Change-Id: I65baffdd27bac1abf744283ff98c2dc864fa63b4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129865
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'solenv')
-rw-r--r-- | solenv/CompilerTest_compilerplugins_clang.mk | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/solenv/CompilerTest_compilerplugins_clang.mk b/solenv/CompilerTest_compilerplugins_clang.mk index 93ebf8468228..66b0579dd69b 100644 --- a/solenv/CompilerTest_compilerplugins_clang.mk +++ b/solenv/CompilerTest_compilerplugins_clang.mk @@ -95,6 +95,7 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \ compilerplugins/clang/test/stringview \ compilerplugins/clang/test/stringviewparam \ compilerplugins/clang/test/typedefparam \ + compilerplugins/clang/test/typeidcomparison \ compilerplugins/clang/test/unnecessarycatchthrow \ compilerplugins/clang/test/unnecessaryoverride \ compilerplugins/clang/test/unnecessaryoverride-dtor \ |