[libcxx-commits] [libcxx] Speed up compilation of common uses of std::visit() (PR #164196)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 29 16:52:05 PDT 2026


================
@@ -1332,6 +1332,10 @@ private:
   friend struct __variant_detail::__visitation::__variant;
 };
 
+template <class... _Types>
+variant<_Types...> __upcast_to_variant(const volatile variant<_Types...>*);
----------------
higher-performance wrote:

I think the upcast is important. Otherwise, you end up with `__vs.__first_variant_type::index()` being called. But in that case `__first_variant_type` is not necessarily a `std::variant`; it might be a derived class, causing the wrong `index()` method to get called. I'll add a comment to clarify.

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


More information about the libcxx-commits mailing list