From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 1B2323857C7A; Fri, 26 Nov 2021 16:35:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B2323857C7A MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r10-10308] libstdc++: Constrain std::make_any [PR102894] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: b3f135a50c3dd7fc04252e17d7fbb08ca95aa9a5 X-Git-Newrev: 923637b6cb70986e83ae0109ec4bcd26fdfe3624 Message-Id: <20211126163501.1B2323857C7A@sourceware.org> Date: Fri, 26 Nov 2021 16:35:01 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Nov 2021 16:35:01 -0000 https://gcc.gnu.org/g:923637b6cb70986e83ae0109ec4bcd26fdfe3624 commit r10-10308-g923637b6cb70986e83ae0109ec4bcd26fdfe3624 Author: Jonathan Wakely Date: Fri Oct 22 22:55:00 2021 +0100 libstdc++: Constrain std::make_any [PR102894] std::make_any should be constrained so it can only be called if the construction of the return value would be valid. libstdc++-v3/ChangeLog: PR libstdc++/102894 * include/std/any (make_any): Add SFINAE constraint. * testsuite/20_util/any/102894.cc: New test. (cherry picked from commit 0c1f737a485f05c591c94b50acfb416c45a4c916) Diff: --- libstdc++-v3/include/std/any | 13 +++++++++---- libstdc++-v3/testsuite/20_util/any/102894.cc | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/std/any b/libstdc++-v3/include/std/any index 16723c3a304..1428858d600 100644 --- a/libstdc++-v3/include/std/any +++ b/libstdc++-v3/include/std/any @@ -411,16 +411,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Exchange the states of two @c any objects. inline void swap(any& __x, any& __y) noexcept { __x.swap(__y); } - /// Create an any holding a @c _Tp constructed from @c __args. + /// Create an `any` holding a `_Tp` constructed from `__args...`. template - any make_any(_Args&&... __args) + inline + enable_if_t, _Args...>, any> + make_any(_Args&&... __args) { return any(in_place_type<_Tp>, std::forward<_Args>(__args)...); } - /// Create an any holding a @c _Tp constructed from @c __il and @c __args. + /// Create an `any` holding a `_Tp` constructed from `__il` and `__args...`. template - any make_any(initializer_list<_Up> __il, _Args&&... __args) + inline + enable_if_t, + initializer_list<_Up>&, _Args...>, any> + make_any(initializer_list<_Up> __il, _Args&&... __args) { return any(in_place_type<_Tp>, __il, std::forward<_Args>(__args)...); } diff --git a/libstdc++-v3/testsuite/20_util/any/102894.cc b/libstdc++-v3/testsuite/20_util/any/102894.cc new file mode 100644 index 00000000000..66ea9a03fea --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/any/102894.cc @@ -0,0 +1,20 @@ +// { dg-do compile { target c++17 } } +#include + +template +struct can_make_any +: std::false_type +{ }; + +template +struct can_make_any())>> +: std::true_type +{ }; + +struct move_only +{ + move_only() = default; + move_only(move_only&&) = default; +}; + +static_assert( ! can_make_any::value ); // PR libstdc++/102894