Make any_cast<void()>(nullptr) compile
llvm-svn: 284333
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: c5777f4d580a37f073b0351de26711d789433486
diff --git a/include/any b/include/any
index 7f2cf1e..229daca 100644
--- a/include/any
+++ b/include/any
@@ -622,6 +622,18 @@
return _VSTD::any_cast<_ValueType>(const_cast<any *>(__any));
}
+template <class _RetType>
+inline _LIBCPP_INLINE_VISIBILITY
+_RetType __pointer_or_func_cast(void* __p, /*IsFunction*/false_type) noexcept {
+ return static_cast<_RetType>(__p);
+}
+
+template <class _RetType>
+inline _LIBCPP_INLINE_VISIBILITY
+_RetType __pointer_or_func_cast(void*, /*IsFunction*/true_type) noexcept {
+ return nullptr;
+}
+
template <class _ValueType>
add_pointer_t<_ValueType>
any_cast(any * __any) _NOEXCEPT
@@ -631,15 +643,15 @@
"_ValueType may not be a reference.");
typedef typename add_pointer<_ValueType>::type _ReturnType;
if (__any && __any->__h) {
- return static_cast<_ReturnType>(
- __any->__call(_Action::_Get, nullptr,
+ void *__p = __any->__call(_Action::_Get, nullptr,
#if !defined(_LIBCPP_NO_RTTI)
&typeid(_ValueType),
#else
nullptr,
#endif
- __any_imp::__get_fallback_typeid<_ValueType>()
- ));
+ __any_imp::__get_fallback_typeid<_ValueType>());
+ return _VSTD::__pointer_or_func_cast<_ReturnType>(
+ __p, is_function<_ValueType>{});
}
return nullptr;
}