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

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jan 3 22:30:35 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 {
----------------
frederick-vs-ja wrote:

I used to think this `any_cast<Func>(ptr)` will trigger warning on unused parameter (`-Wunused-parameter`). But it seems that the waring is suppressed. I'll remove `[[maybe_unused]]`.

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


More information about the libcxx-commits mailing list