[libcxx-commits] [libcxx] [libc++][NFC] Replace tag dispatch with `if constexpr` in `<any>` and `<variant>` (PR #173538)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jan 3 07:43:08 PST 2026


================
@@ -544,33 +544,25 @@ template <class _ValueType>
   return std::any_cast<_ValueType>(const_cast<any*>(__any));
 }
 
-template <class _RetType>
-inline _LIBCPP_HIDE_FROM_ABI _RetType __pointer_or_func_cast(void* __p, /*IsFunction*/ false_type) noexcept {
-  return static_cast<_RetType>(__p);
-}
-
-template <class _RetType>
-inline _LIBCPP_HIDE_FROM_ABI _RetType __pointer_or_func_cast(void*, /*IsFunction*/ true_type) noexcept {
-  return nullptr;
-}
-
 template <class _ValueType>
-[[nodiscard]] _LIBCPP_HIDE_FROM_ABI add_pointer_t<_ValueType> any_cast(any* __any) _NOEXCEPT {
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI add_pointer_t<_ValueType> any_cast([[maybe_unused]] any* __any) _NOEXCEPT {
----------------
philnik777 wrote:

```suggestion
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _ValueType* any_cast([[maybe_unused]] any* __any) _NOEXCEPT {
```
I don't think there is any reason to use `add_pointer_t`?

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


More information about the libcxx-commits mailing list