summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/compat.hxx
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2022-08-08 14:09:42 +0200
committerStephan Bergmann <sbergman@redhat.com>2022-08-08 21:04:10 +0200
commitfb992aefc8345a9be780c6928e4380da7c56904e (patch)
treeeb71352fff93df92f4e09cf81bd602b12e3b64cd /compilerplugins/clang/compat.hxx
parent00f3bbc84634a9f07c046140d84445303585817c (diff)
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 <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins/clang/compat.hxx')
-rw-r--r--compilerplugins/clang/compat.hxx19
1 files changed, 19 insertions, 0 deletions
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);