[llvm] [ADT] Specialize ValueIsPresent for PointerUnion (PR #121847)

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 7 17:20:07 PST 2025


================
@@ -259,6 +259,17 @@ struct CastInfo<To, const PointerUnion<PTs...>>
                                           CastInfo<To, PointerUnion<PTs...>>> {
 };
 
+// The default implementation of isPresent() for nullable types returns true
+// if the active member is not the first one, even if its value is nullptr.
+// Override the default behavior to return false for all possible null values.
+template <typename... PTs>
+struct ValueIsPresent<PointerUnion<PTs...>,
+                      std::enable_if_t<IsNullable<PointerUnion<PTs...>>>> {
+  using Union = PointerUnion<PTs...>;
+  static bool isPresent(const Union &V) { return static_cast<bool>(V); }
+  static decltype(auto) unwrapValue(Union &V) { return V; }
----------------
kuhar wrote:

```suggestion
  static Union &unwrapValue(Union &V) { return V; }
```

I don't think `decltype(auto)` helps here?

https://github.com/llvm/llvm-project/pull/121847


More information about the llvm-commits mailing list