diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2021-01-20 08:02:19 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2021-01-20 11:27:33 +0100 |
commit | 4b55847b81fa18d5bf2445c294b9260e98f365bc (patch) | |
tree | 85065a2335f51292f39031af892e8ad97e8db4b7 /compilerplugins/clang/compat.hxx | |
parent | 04e2aa34303424456b9db46ab1300eb103f40a03 (diff) |
Improve loplugin:doubleconvert
(The use of isa_and_nonnull<> instead of isa<> is necessary for cases like
return (i_styleSettings.*i_getDefaultColor)();
in lcl_getEffectiveColor, svtools/source/table/gridtablerenderer.cxx.)
Change-Id: Iffc59b1146dd4ce13bbd3c8a6f46bd3c78a39344
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109663
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins/clang/compat.hxx')
-rw-r--r-- | compilerplugins/clang/compat.hxx | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/compilerplugins/clang/compat.hxx b/compilerplugins/clang/compat.hxx index bf3abf60c941..ae7557b71956 100644 --- a/compilerplugins/clang/compat.hxx +++ b/compilerplugins/clang/compat.hxx @@ -20,12 +20,26 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" #include "config_clang.h" // Compatibility wrapper to abstract over (trivial) changes in the Clang API: namespace compat { +// Copies code from LLVM's include/llvm/Support/Casting.h: +template<typename... X, typename Y> LLVM_NODISCARD inline bool isa_and_nonnull(Y const & Val) { +#if CLANG_VERSION >= 90000 + return llvm::isa_and_nonnull<X...>(Val); +#else + if (!Val) { + return false; + } + return llvm::isa<X...>(Val); +#endif +} + inline clang::SourceLocation getBeginLoc(clang::Decl const * decl) { #if CLANG_VERSION >= 80000 return decl->getBeginLoc(); |