2017-01-20 Jonathan Wakely <jwakely@redhat.com>
+ PR libstdc++/69321
+ * include/experimental/any (__any_caster): Avoid instantiating
+ manager function for types that can't be stored in any.
+ * include/std/any (__any_caster): Likewise.
+ * testsuite/20_util/any/misc/any_cast.cc: Test non-copyable type.
+ * testsuite/experimental/any/misc/any_cast.cc: Likewise.
+
PR libstdc++/64903
* include/bits/stl_algo.h (is_partitioned): Use increment instead of
std::advance.
template<typename _Tp>
void* __any_caster(const any* __any)
{
- if (__any->_M_manager != &any::_Manager<decay_t<_Tp>>::_S_manage)
+ struct _None { };
+ using _Up = decay_t<_Tp>;
+ using _Vp = conditional_t<is_copy_constructible<_Up>::value, _Up, _None>;
+ if (__any->_M_manager != &any::_Manager<_Vp>::_S_manage)
return nullptr;
any::_Arg __arg;
__any->_M_manager(any::_Op_access, __any, &__arg);
template<typename _Tp>
void* __any_caster(const any* __any)
{
- if (__any->_M_manager != &any::_Manager<decay_t<_Tp>>::_S_manage)
- return nullptr;
- any::_Arg __arg;
- __any->_M_manager(any::_Op_access, __any, &__arg);
- return __arg._M_obj;
+ if constexpr (is_copy_constructible_v<decay_t<_Tp>>)
+ {
+ if (__any->_M_manager == &any::_Manager<decay_t<_Tp>>::_S_manage)
+ {
+ any::_Arg __arg;
+ __any->_M_manager(any::_Op_access, __any, &__arg);
+ return __arg._M_obj;
+ }
+ }
+ return nullptr;
}
/**
ExplicitCopy ec2{any_cast<ExplicitCopy>(std::move(x))};
}
+void test05()
+{
+ // PR libstdc++/69321
+ struct noncopyable {
+ noncopyable(noncopyable const&) = delete;
+ };
+
+ any a;
+ auto p = any_cast<noncopyable>(&a);
+ VERIFY( p == nullptr );
+}
+
int main()
{
test01();
test02();
test03();
test04();
+ test05();
}
MoveDeleted&& md3 = any_cast<MoveDeleted&&>(any(std::move(md)));
}
+void test04()
+{
+ // PR libstdc++/69321
+ struct noncopyable {
+ noncopyable(noncopyable const&) = delete;
+ };
+
+ any a;
+ auto p = any_cast<noncopyable>(&a);
+ VERIFY( p == nullptr );
+}
+
int main()
{
test01();
test02();
test03();
+ test04();
}