compilerplugins/clang/compat.hxx | 19 +++++++++++++++++++ compilerplugins/clang/pointerbool.cxx | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-)
New commits: commit fb992aefc8345a9be780c6928e4380da7c56904e Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Mon Aug 8 14:09:42 2022 +0200 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Mon Aug 8 21:04:10 2022 +0200 Adapt to changes in llvm::Optional <https://github.com/llvm/llvm-project/commit/3c49576417bab1b07764aa0b22664cbc8d3c3f53> "[ADT] Add has_value, value, value_or to llvm::Optional" is in Clang 15, and <https://github.com/llvm/llvm-project/commit/b5f8d42efe3e246d582d4a1a328fac915e4ce8dc> "[ADT] Deprecate Optional::{hasValue,getValue} (NFC)" is in Clang 16 trunk, causing > In file included from compilerplugins/clang/sharedvisitor/sharedvisitor.cxx:95: > compilerplugins/clang/pointerbool.cxx:118:21: error: 'hasValue' is deprecated: Use has_value instead. [-Werror,-Wdeprecated-declarations] > if (ret.hasValue() && (ret.getValue() == 1 || ret.getValue() == 0)) > ^ > ~/llvm/inst/include/llvm/ADT/Optional.h:324:5: note: 'hasValue' has been explicitly marked deprecated here > [[deprecated("Use has_value instead.")]] constexpr bool hasValue() const { > ^ etc. Change-Id: I377effe29fc6752484d2870b9a0fd66fddc26bfc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137982 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/compilerplugins/clang/compat.hxx b/compilerplugins/clang/compat.hxx index 1a6266ec5201..625e43220206 100644 --- a/compilerplugins/clang/compat.hxx +++ b/compilerplugins/clang/compat.hxx @@ -16,6 +16,7 @@ #include "clang/AST/ExprCXX.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/Specifiers.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/FileSystem.h" @@ -24,6 +25,24 @@ // Compatibility wrapper to abstract over (trivial) changes in the Clang API: namespace compat { +template<typename T> +constexpr bool has_value(llvm::Optional<T> const & o) { +#if CLANG_VERSION >= 150000 + return o.has_value(); +#else + return o.hasValue(); +#endif +} + +template<typename T> +constexpr T const & value(llvm::Optional<T> const & o) { +#if CLANG_VERSION >= 150000 + return o.value(); +#else + return o.getValue(); +#endif +} + inline std::string toString(llvm::APSInt const & i, unsigned radix) { #if CLANG_VERSION >= 130000 return llvm::toString(i, radix); diff --git a/compilerplugins/clang/pointerbool.cxx b/compilerplugins/clang/pointerbool.cxx index 3bc87e743e98..9e6f3068358e 100644 --- a/compilerplugins/clang/pointerbool.cxx +++ b/compilerplugins/clang/pointerbool.cxx @@ -115,7 +115,7 @@ bool PointerBool::VisitCallExpr(CallExpr const* callExpr) if (arg->getType()->isIntegerType()) { auto ret = getCallValue(arg); - if (ret.hasValue() && (ret.getValue() == 1 || ret.getValue() == 0)) + if (compat::has_value(ret) && (compat::value(ret) == 1 || compat::value(ret) == 0)) continue; // something like: priv->m_nLOKFeatures & LOK_FEATURE_DOCUMENT_PASSWORD if (isa<BinaryOperator>(arg->IgnoreParenImpCasts()))