template<typename _ValueType>
inline const _ValueType* any_cast(const any* __any) noexcept
{
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 3305. any_cast<void>
+ static_assert(!is_void_v<_ValueType>);
+
+ // As an optimization, don't bother instantiating __any_caster for
+ // function types, since std::any can only hold objects.
if constexpr (is_object_v<_ValueType>)
if (__any)
return static_cast<_ValueType*>(__any_caster<_ValueType>(__any));
template<typename _ValueType>
inline _ValueType* any_cast(any* __any) noexcept
{
+ static_assert(!is_void_v<_ValueType>);
+
if constexpr (is_object_v<_ValueType>)
if (__any)
return static_cast<_ValueType*>(__any_caster<_ValueType>(__any));
--- /dev/null
+// { dg-do compile { target c++17 } }
+
+// LWG 3305. any_cast<void>
+
+#include <any>
+
+void
+test_lwg3305()
+{
+ std::any a;
+ (void) std::any_cast<const void>(&a); // { dg-error "here" }
+ const std::any a2;
+ (void) std::any_cast<volatile void>(&a2); // { dg-error "here" }
+}
+// { dg-error "static assertion failed" "" { target *-*-* } 0 }