From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 055BA3858C33; Wed, 24 Aug 2022 20:39:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 055BA3858C33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661373578; bh=ReUf24/nCL1kqp27snUotJdPM2GLbuhfOsiCYXlEOeI=; h=From:To:Subject:Date:From; b=XkfbcnOKX2owHDsSR54Gzr1iVVdvw3AVpANAsUHpBn1e2n6pxdXv5eFwW0niiDwhE FlI6ZWmOWkXRPs7ON7LK4451UCBH/QJcovmtFxzkByyYB1F1rcho8yeo19+v9n6zBx 1uCEODyCBLCh7ngcct1pkOYZG01HNzpzNq8fP+iI= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-2191] libstdc++: Fix fallout from P2321R2 std::pair/tuple enhancements X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: df5204ddd4b8e3a2d02bb3ad5bcdb9d636b02537 X-Git-Newrev: f46f58e61db3b1e71beb21443c0ca9387bc836e2 Message-Id: <20220824203938.055BA3858C33@sourceware.org> Date: Wed, 24 Aug 2022 20:39:38 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f46f58e61db3b1e71beb21443c0ca9387bc836e2 commit r13-2191-gf46f58e61db3b1e71beb21443c0ca9387bc836e2 Author: Patrick Palka Date: Wed Aug 24 16:38:45 2022 -0400 libstdc++: Fix fallout from P2321R2 std::pair/tuple enhancements r13-2159-g72886fcc626953 caused some testsuite regressions in C++23 mode: FAIL: 20_util/pair/requirements/explicit_instantiation/1.cc (test for excess errors) FAIL: 20_util/tuple/53648.cc (test for excess errors) FAIL: 20_util/tuple/cons/noexcept_specs.cc (test for excess errors) FAIL: 20_util/tuple/requirements/explicit_instantiation.cc (test for excess errors) The test noexcept_specs.cc just needs to be updated to consider the additional converting constructors of tuple in C++23 mode, which happen to improve constructing from a const tuple rvalue that has an rvalue reference element (for the better, as far as I can tell). The other three tests fail because they explicitly instantiate a specialization of pair/tuple whose elements are not all const swappable, which in C++23 mode now results in a hard error due to the new const swap member function. Rather than XFAILing the tests in C++23 mode, this patch adds non-standard constraints to this member function so that we continue to accept such explicit instantiations. libstdc++-v3/ChangeLog: * include/bits/stl_pair.h (pair::swap const): Add non-standard is_swappable_v constraints. * include/std/tuple (tuple::swap const): Likewise. * testsuite/20_util/tuple/cons/noexcept_specs.cc: Correct some asserts in C++23 mode. Diff: --- libstdc++-v3/include/bits/stl_pair.h | 7 ++++ libstdc++-v3/include/std/tuple | 8 +++++ .../testsuite/20_util/tuple/cons/noexcept_specs.cc | 41 ++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/libstdc++-v3/include/bits/stl_pair.h b/libstdc++-v3/include/bits/stl_pair.h index bffca0daf65..d0f07b09d34 100644 --- a/libstdc++-v3/include/bits/stl_pair.h +++ b/libstdc++-v3/include/bits/stl_pair.h @@ -213,10 +213,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } #if __cplusplus > 202002L + // As an extension, we constrain the const swap member function in order + // to continue accepting explicit instantiation of pairs whose elements + // are not all const swappable. Without this constraint, such an + // explicit instantiation would also instantiate the ill-formed body of + // this function and yield a hard error. This constraint shouldn't + // affect the behavior of valid programs. constexpr void swap(const pair& __p) const noexcept(__and_v<__is_nothrow_swappable, __is_nothrow_swappable>) + requires is_swappable_v && is_swappable_v { using std::swap; swap(first, __p.first); diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index 05433d5ae36..ddd7c226d80 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -1176,9 +1176,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { _Inherited::_M_swap(__in); } #if __cplusplus > 202002L + // As an extension, we constrain the const swap member function in order + // to continue accepting explicit instantiation of tuples whose elements + // are not all const swappable. Without this constraint, such an + // explicit instantiation would also instantiate the ill-formed body of + // this function and yield a hard error. This constraint shouldn't + // affect the behavior of valid programs. constexpr void swap(const tuple& __in) const noexcept(__and_v<__is_nothrow_swappable...>) + requires (is_swappable_v && ...) { _Inherited::_M_swap(__in); } #endif // C++23 }; @@ -1730,6 +1737,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION swap(const tuple& __in) const noexcept(__and_v<__is_nothrow_swappable, __is_nothrow_swappable>) + requires is_swappable_v && is_swappable_v { _Inherited::_M_swap(__in); } #endif // C++23 }; diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/noexcept_specs.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/noexcept_specs.cc index 6044a377348..a326d1bc228 100644 --- a/libstdc++-v3/testsuite/20_util/tuple/cons/noexcept_specs.cc +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/noexcept_specs.cc @@ -503,7 +503,17 @@ namespace NothrowCopyThrowMoveThrowCopyConversionNothrowMoveConversion static_assert(!std::is_nothrow_constructible::value, ""); static_assert(!std::is_nothrow_constructible::value, ""); static_assert(!std::is_nothrow_constructible>::value, ""); +#if __cplusplus > 202002L + // C++23 extended tuple's constructor overload set as part of P2321R2, after + // which its converting constructors more accurately forward the elements + // from a non-const tuple lvalue and from a const tuple rvalue. In particular + // for the below test we now forward int&& as an rvalue reference instead of + // as an lvalue reference, which means we now select the noexcept B(int&&) + // ctor instead of the non-noexcept B(const int&) ctor. + static_assert(std::is_nothrow_constructible>::value, ""); +#else static_assert(!std::is_nothrow_constructible>::value, ""); +#endif static_assert(test_trait::is_nothrow_convertible::value,""); static_assert(!test_trait::is_nothrow_convertible::value,""); @@ -515,7 +525,13 @@ namespace NothrowCopyThrowMoveThrowCopyConversionNothrowMoveConversion static_assert(!test_trait::is_nothrow_convertible::value,""); static_assert(!test_trait::is_nothrow_convertible::value,""); static_assert(!test_trait::is_nothrow_convertible,BT>::value,""); +#if __cplusplus > 202002L + // See the note about P2321R2 above. + static_assert(test_trait::is_nothrow_convertible,BT>::value,""); +#else static_assert(!test_trait::is_nothrow_convertible,BT>::value,""); +#endif + static_assert(!std::is_nothrow_constructible::value, ""); @@ -528,7 +544,12 @@ namespace NothrowCopyThrowMoveThrowCopyConversionNothrowMoveConversion static_assert(std::is_nothrow_constructible::value, ""); static_assert(std::is_nothrow_constructible::value, ""); static_assert(std::is_nothrow_constructible>::value, ""); +#if __cplusplus > 202002L + // See the note about P2321R2 above. + static_assert(!std::is_nothrow_constructible>::value, ""); +#else static_assert(std::is_nothrow_constructible>::value, ""); +#endif static_assert(!test_trait::is_nothrow_convertible::value,""); static_assert(test_trait::is_nothrow_convertible::value,""); @@ -540,7 +561,12 @@ namespace NothrowCopyThrowMoveThrowCopyConversionNothrowMoveConversion static_assert(test_trait::is_nothrow_convertible::value,""); static_assert(test_trait::is_nothrow_convertible::value,""); static_assert(test_trait::is_nothrow_convertible,BT>::value,""); +#if __cplusplus > 202002L + // See the note about P2321R2 above. + static_assert(!test_trait::is_nothrow_convertible,BT>::value,""); +#else static_assert(test_trait::is_nothrow_convertible,BT>::value,""); +#endif /* explicit */ static_assert(std::is_nothrow_constructible::value, ""); @@ -553,7 +579,12 @@ namespace NothrowCopyThrowMoveThrowCopyConversionNothrowMoveConversion static_assert(!std::is_nothrow_constructible::value, ""); static_assert(!std::is_nothrow_constructible::value, ""); static_assert(!std::is_nothrow_constructible>::value, ""); +#if __cplusplus > 202002L + // See the note about P2321R2 above. + static_assert(std::is_nothrow_constructible>::value, ""); +#else static_assert(!std::is_nothrow_constructible>::value, ""); +#endif static_assert(!std::is_nothrow_constructible::value, ""); static_assert(std::is_nothrow_constructible::value, ""); @@ -565,7 +596,12 @@ namespace NothrowCopyThrowMoveThrowCopyConversionNothrowMoveConversion static_assert(std::is_nothrow_constructible::value, ""); static_assert(std::is_nothrow_constructible::value, ""); static_assert(std::is_nothrow_constructible>::value, ""); +#if __cplusplus > 202002L + // See note about P2321R2 above. + static_assert(!std::is_nothrow_constructible>::value, ""); +#else static_assert(std::is_nothrow_constructible>::value, ""); +#endif static_assert(!test_trait::is_nothrow_convertible::value,""); static_assert(test_trait::is_nothrow_convertible::value,""); @@ -884,7 +920,12 @@ namespace ThrowMoveNothrowConversion static_assert(std::is_nothrow_constructible::value, ""); static_assert(std::is_nothrow_constructible::value, ""); static_assert(std::is_nothrow_constructible>::value, ""); +#if __cplusplus > 202002L + // See the note about P2321R2 above. + static_assert(!std::is_nothrow_constructible>::value, ""); +#else static_assert(std::is_nothrow_constructible>::value, ""); +#endif static_assert(test_trait::is_nothrow_convertible::value,""); static_assert(test_trait::is_nothrow_convertible::value,"");