@@ -198,14 +198,14 @@ class PointerUnion
198198 }
199199};
200200
201- template <typename ... PTs>
202- bool operator ==(PointerUnion<PTs...> LHS , PointerUnion<PTs...> RHS ) {
203- return (!LHS && !RHS) || LHS .getOpaqueValue () == RHS .getOpaqueValue ();
201+ template <typename ...PTs>
202+ bool operator ==(PointerUnion<PTs...> lhs , PointerUnion<PTs...> rhs ) {
203+ return lhs .getOpaqueValue () == rhs .getOpaqueValue ();
204204}
205205
206- template <typename ... PTs>
207- bool operator !=(PointerUnion<PTs...> LHS , PointerUnion<PTs...> RHS ) {
208- return ! operator ==(LHS, RHS );
206+ template <typename ...PTs>
207+ bool operator !=(PointerUnion<PTs...> lhs , PointerUnion<PTs...> rhs ) {
208+ return lhs. getOpaqueValue () != rhs. getOpaqueValue ( );
209209}
210210
211211template <typename ...PTs>
@@ -259,6 +259,17 @@ 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 decltype (auto ) unwrapValue(Union &V) { return V; }
271+ };
272+
262273// Teach SmallPtrSet that PointerUnion is "basically a pointer", that has
263274// # low bits available = min(PT1bits,PT2bits)-1.
264275template <typename ...PTs>
0 commit comments