[llvm] [ADT] Specialize ValueIsPresent for PointerUnion (PR #121847)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 8 16:18:38 PST 2025
================
@@ -614,12 +614,11 @@ template <typename T> struct ValueIsPresent<std::optional<T>> {
static inline decltype(auto) unwrapValue(std::optional<T> &t) { return *t; }
};
-// If something is "nullable" then we just compare it to nullptr to see if it
-// exists.
+// If something is "nullable" then we just cast it to bool to see if it exists.
template <typename T>
struct ValueIsPresent<T, std::enable_if_t<IsNullable<T>>> {
using UnwrappedType = T;
- static inline bool isPresent(const T &t) { return t != T(nullptr); }
+ static inline bool isPresent(const T &t) { return static_cast<bool>(t); }
----------------
s-barannikov wrote:
It appears `is_convertible` only handles implicit conversions, i.e. it returns false for types with `explicit operator bool()`. I used `is_constructible` with swapped arguments instead.
https://github.com/llvm/llvm-project/pull/121847
More information about the llvm-commits
mailing list