Skip to content

Commit 62157bf

Browse files
committed
Change the specialization for nullable types to cast to bool
1 parent 294c617 commit 62157bf

File tree

2 files changed

+2
-14
lines changed

2 files changed

+2
-14
lines changed

llvm/include/llvm/ADT/PointerUnion.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,6 @@ struct CastInfo<To, const PointerUnion<PTs...>>
259259
CastInfo<To, PointerUnion<PTs...>>> {
260260
};
261261

262-
// The default implementation of isPresent() for nullable types returns true
263-
// if the active member is not the first one, even if its value is nullptr.
264-
// Override the default behavior to return false for all possible null values.
265-
template <typename... PTs>
266-
struct ValueIsPresent<PointerUnion<PTs...>,
267-
std::enable_if_t<IsNullable<PointerUnion<PTs...>>>> {
268-
using Union = PointerUnion<PTs...>;
269-
static bool isPresent(const Union &V) { return static_cast<bool>(V); }
270-
static Union &unwrapValue(Union &V) { return V; }
271-
};
272-
273262
// Teach SmallPtrSet that PointerUnion is "basically a pointer", that has
274263
// # low bits available = min(PT1bits,PT2bits)-1.
275264
template <typename ...PTs>

llvm/include/llvm/Support/Casting.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,11 @@ template <typename T> struct ValueIsPresent<std::optional<T>> {
614614
static inline decltype(auto) unwrapValue(std::optional<T> &t) { return *t; }
615615
};
616616

617-
// If something is "nullable" then we just compare it to nullptr to see if it
618-
// exists.
617+
// If something is "nullable" then we just cast it to bool to see if it exists.
619618
template <typename T>
620619
struct ValueIsPresent<T, std::enable_if_t<IsNullable<T>>> {
621620
using UnwrappedType = T;
622-
static inline bool isPresent(const T &t) { return t != T(nullptr); }
621+
static inline bool isPresent(const T &t) { return static_cast<bool>(t); }
623622
static inline decltype(auto) unwrapValue(T &t) { return t; }
624623
};
625624

0 commit comments

Comments
 (0)