From: Ville Voutilainen Date: Mon, 15 Aug 2016 15:06:09 +0000 (+0300) Subject: Implement LWG 2744 and LWG 2754. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5c578ae4348bddb97991348c2d0a05e3e7d7ad5a;p=gcc.git Implement LWG 2744 and LWG 2754. * include/std/any (any(ValueType&&)): Constrain with __is_in_place_type. (any(in_place_type_t<_ValueType>, _Args&&...)): Use _Decay. (any(in_place_type_t<_ValueType>, initializer_list<_Up>, _Args&&...)): Likewise. (emplace(_Args&&...)): Likewise. (emplace(initializer_list<_Up>, _Args&&...)): Likewise. * include/std/utility: (__is_in_place_type_impl): New. (__is_in_place_type): Likewise. * testsuite/20_util/any/assign/emplace.cc: Add tests for decaying emplace. * testsuite/20_util/any/cons/in_place.cc: Add tests for decaying in_place constructor. * testsuite/20_util/any/misc/any_cast_neg.cc: Adjust. * testsuite/20_util/any/requirements.cc: Add a test for in_place-constructing a non-default-constructible type. From-SVN: r239482 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 05ee02a1398..73ddaac385d 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,22 @@ +2016-08-15 Ville Voutilainen + + Implement LWG 2744 and LWG 2754. + * include/std/any (any(ValueType&&)): Constrain with __is_in_place_type. + (any(in_place_type_t<_ValueType>, _Args&&...)): Use _Decay. + (any(in_place_type_t<_ValueType>, initializer_list<_Up>, _Args&&...)): + Likewise. + (emplace(_Args&&...)): Likewise. + (emplace(initializer_list<_Up>, _Args&&...)): Likewise. + * include/std/utility: (__is_in_place_type_impl): New. + (__is_in_place_type): Likewise. + * testsuite/20_util/any/assign/emplace.cc: Add tests for decaying + emplace. + * testsuite/20_util/any/cons/in_place.cc: Add tests for decaying + in_place constructor. + * testsuite/20_util/any/misc/any_cast_neg.cc: Adjust. + * testsuite/20_util/any/requirements.cc: Add a test for + in_place-constructing a non-default-constructible type. + 2016-08-15 Ville Voutilainen Add a feature macro for C++17 make_from_tuple. diff --git a/libstdc++-v3/include/std/any b/libstdc++-v3/include/std/any index 4add1186923..9160035006e 100644 --- a/libstdc++-v3/include/std/any +++ b/libstdc++-v3/include/std/any @@ -153,7 +153,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Construct with a copy of @p __value as the contained object. template , typename _Mgr = _Manager<_Tp>, - __any_constructible_t<_Tp, _ValueType&&> = true> + __any_constructible_t<_Tp, _ValueType&&> = true, + enable_if_t::value, bool> = true> any(_ValueType&& __value) : _M_manager(&_Mgr::_S_manage) { @@ -164,9 +165,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template , typename _Mgr = _Manager<_Tp>, enable_if_t<__and_, - __not_< - is_constructible<_Tp, - _ValueType&&>>>::value, + __not_>, + __not_<__is_in_place_type<_ValueType>>>::value, bool> = false> any(_ValueType&& __value) : _M_manager(&_Mgr::_S_manage) @@ -175,10 +175,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } /// Construct with an object created from @p __args as the contained object. - template , typename _Mgr = _Manager<_Tp>, __any_constructible_t<_Tp, _Args&&...> = false> - any(in_place_type_t<_Tp>, _Args&&... __args) + any(in_place_type_t<_ValueType>, _Args&&... __args) : _M_manager(&_Mgr::_S_manage) { _Mgr::_S_create(_M_storage, std::forward<_Args>(__args)...); @@ -186,11 +187,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Construct with an object created from @p __il and @p __args as /// the contained object. - template , typename _Mgr = _Manager<_Tp>, __any_constructible_t<_Tp, initializer_list<_Up>, _Args&&...> = false> - any(in_place_type_t<_Tp>, initializer_list<_Up> __il, _Args&&... __args) + any(in_place_type_t<_ValueType>, + initializer_list<_Up> __il, _Args&&... __args) : _M_manager(&_Mgr::_S_manage) { _Mgr::_S_create(_M_storage, __il, std::forward<_Args>(__args)...); @@ -248,7 +251,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } /// Emplace with an object created from @p __args as the contained object. - template , typename _Mgr = _Manager<_Tp>, __any_constructible_t<_Tp, _Args&&...> = false> void emplace(_Args&&... __args) @@ -260,7 +264,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Emplace with an object created from @p __il and @p __args as /// the contained object. - template , typename _Mgr = _Manager<_Tp>, __any_constructible_t<_Tp, initializer_list<_Up>, _Args&&...> = false> diff --git a/libstdc++-v3/include/std/utility b/libstdc++-v3/include/std/utility index 0c0364430b6..6a6659b5495 100644 --- a/libstdc++-v3/include/std/utility +++ b/libstdc++-v3/include/std/utility @@ -356,6 +356,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template in_place_tag in_place(__in_place_index<_Idx>*) {terminate();} + template + struct __is_in_place_type_impl : false_type + { }; + + template + struct __is_in_place_type_impl> : true_type + { }; + + template + struct __is_in_place_type + : public __is_in_place_type_impl<_Tp> + { }; + #define __cpp_lib_as_const 201510 template constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; } @@ -363,7 +376,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template void as_const(const _Tp&&) = delete; -#endif +#endif // C++17 _GLIBCXX_END_NAMESPACE_VERSION } // namespace diff --git a/libstdc++-v3/testsuite/20_util/any/assign/emplace.cc b/libstdc++-v3/testsuite/20_util/any/assign/emplace.cc index 663bae27f38..799c5edf4a4 100644 --- a/libstdc++-v3/testsuite/20_util/any/assign/emplace.cc +++ b/libstdc++-v3/testsuite/20_util/any/assign/emplace.cc @@ -59,4 +59,17 @@ int main() combined& c2 = std::any_cast(o5); VERIFY(c2.v[0] == 1 && c2.v[1] == 2 && std::get<0>(c2.t) == 3 && std::get<1>(c2.t) == 4 ); + std::any o6; + o6.emplace(i); + VERIFY(o6.type() == o.type()); + std::any o7; + o7.emplace(nullptr); + std::any o8; + o8.emplace(nullptr); + VERIFY(o7.type() == o8.type()); + std::any o9; + o9.emplace(nullptr); + std::any o10; + o10.emplace(nullptr); + VERIFY(o9.type() == o10.type()); } diff --git a/libstdc++-v3/testsuite/20_util/any/cons/in_place.cc b/libstdc++-v3/testsuite/20_util/any/cons/in_place.cc index 2368b83d250..52f2b38d5fc 100644 --- a/libstdc++-v3/testsuite/20_util/any/cons/in_place.cc +++ b/libstdc++-v3/testsuite/20_util/any/cons/in_place.cc @@ -54,4 +54,12 @@ int main() combined& c2 = std::any_cast(o5); VERIFY(c2.v[0] == 1 && c2.v[1] == 2 && std::get<0>(c2.t) == 3 && std::get<1>(c2.t) == 4 ); + std::any o6(std::in_place, i); + VERIFY(o6.type() == o.type()); + std::any o7(std::in_place, nullptr); + std::any o8(std::in_place, nullptr); + VERIFY(o7.type() == o8.type()); + std::any o9(std::in_place, nullptr); + std::any o10(std::in_place, nullptr); + VERIFY(o9.type() == o10.type()); } diff --git a/libstdc++-v3/testsuite/20_util/any/misc/any_cast_neg.cc b/libstdc++-v3/testsuite/20_util/any/misc/any_cast_neg.cc index 32b4e767fd2..05fdeb7198d 100644 --- a/libstdc++-v3/testsuite/20_util/any/misc/any_cast_neg.cc +++ b/libstdc++-v3/testsuite/20_util/any/misc/any_cast_neg.cc @@ -26,5 +26,5 @@ void test01() using std::any_cast; const any y(1); - any_cast(y); // { dg-error "qualifiers" "" { target { *-*-* } } 435 } + any_cast(y); // { dg-error "qualifiers" "" { target { *-*-* } } 440 } } diff --git a/libstdc++-v3/testsuite/20_util/any/requirements.cc b/libstdc++-v3/testsuite/20_util/any/requirements.cc index f33cd67ffe6..7b084bec64a 100644 --- a/libstdc++-v3/testsuite/20_util/any/requirements.cc +++ b/libstdc++-v3/testsuite/20_util/any/requirements.cc @@ -34,3 +34,11 @@ static_assert(!std::is_assignable&>::value); static_assert(!std::is_constructible&>::value); static_assert(!std::is_assignable&>::value); static_assert(!std::is_constructible&>::value); + +struct NoDefaultCtor +{ + NoDefaultCtor() = delete; +}; + +static_assert(!std::is_constructible>::value);