public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r13-2191] libstdc++: Fix fallout from P2321R2 std::pair/tuple enhancements
Date: Wed, 24 Aug 2022 20:39:38 +0000 (GMT)	[thread overview]
Message-ID: <20220824203938.055BA3858C33@sourceware.org> (raw)

https://gcc.gnu.org/g:f46f58e61db3b1e71beb21443c0ca9387bc836e2

commit r13-2191-gf46f58e61db3b1e71beb21443c0ca9387bc836e2
Author: Patrick Palka <ppalka@redhat.com>
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<const _T1>,
 		       __is_nothrow_swappable<const _T2>>)
+      requires is_swappable_v<const _T1> && is_swappable_v<const _T2>
       {
 	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<const _Elements>...>)
+      requires (is_swappable_v<const _Elements> && ...)
       { _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<const _T1>,
 		       __is_nothrow_swappable<const _T2>>)
+      requires is_swappable_v<const _T1> && is_swappable_v<const _T2>
       { _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<BT, IT&>::value, "");
   static_assert(!std::is_nothrow_constructible<BT, const IT &>::value, "");
   static_assert(!std::is_nothrow_constructible<BT, std::tuple<int&>>::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<BT, const std::tuple<int&&>>::value, "");
+#else
   static_assert(!std::is_nothrow_constructible<BT, const std::tuple<int&&>>::value, "");
+#endif
 
   static_assert(test_trait::is_nothrow_convertible<int,BT>::value,"");
   static_assert(!test_trait::is_nothrow_convertible<const int,BT>::value,"");
@@ -515,7 +525,13 @@ namespace NothrowCopyThrowMoveThrowCopyConversionNothrowMoveConversion
   static_assert(!test_trait::is_nothrow_convertible<IT&,BT>::value,"");
   static_assert(!test_trait::is_nothrow_convertible<const IT &,BT>::value,"");
   static_assert(!test_trait::is_nothrow_convertible<std::tuple<int&>,BT>::value,"");
+#if __cplusplus > 202002L
+  // See the note about P2321R2 above.
+  static_assert(test_trait::is_nothrow_convertible<const std::tuple<int&&>,BT>::value,"");
+#else
   static_assert(!test_trait::is_nothrow_convertible<const std::tuple<int&&>,BT>::value,"");
+#endif
+
 
 
   static_assert(!std::is_nothrow_constructible<BT, B>::value, "");
@@ -528,7 +544,12 @@ namespace NothrowCopyThrowMoveThrowCopyConversionNothrowMoveConversion
   static_assert(std::is_nothrow_constructible<BT, BT&>::value, "");
   static_assert(std::is_nothrow_constructible<BT, const BT &>::value, "");
   static_assert(std::is_nothrow_constructible<BT, std::tuple<B&>>::value, "");
+#if __cplusplus > 202002L
+  // See the note about P2321R2 above.
+  static_assert(!std::is_nothrow_constructible<BT, const std::tuple<B&&>>::value, "");
+#else
   static_assert(std::is_nothrow_constructible<BT, const std::tuple<B&&>>::value, "");
+#endif
 
   static_assert(!test_trait::is_nothrow_convertible<B,BT>::value,"");
   static_assert(test_trait::is_nothrow_convertible<const B,BT>::value,"");
@@ -540,7 +561,12 @@ namespace NothrowCopyThrowMoveThrowCopyConversionNothrowMoveConversion
   static_assert(test_trait::is_nothrow_convertible<BT&,BT>::value,"");
   static_assert(test_trait::is_nothrow_convertible<const BT &,BT>::value,"");
   static_assert(test_trait::is_nothrow_convertible<std::tuple<B&>,BT>::value,"");
+#if __cplusplus > 202002L
+  // See the note about P2321R2 above.
+  static_assert(!test_trait::is_nothrow_convertible<const std::tuple<B&&>,BT>::value,"");
+#else
   static_assert(test_trait::is_nothrow_convertible<const std::tuple<B&&>,BT>::value,"");
+#endif
 
 /* explicit */
   static_assert(std::is_nothrow_constructible<DT, int>::value, "");
@@ -553,7 +579,12 @@ namespace NothrowCopyThrowMoveThrowCopyConversionNothrowMoveConversion
   static_assert(!std::is_nothrow_constructible<DT, IT&>::value, "");
   static_assert(!std::is_nothrow_constructible<DT, const IT &>::value, "");
   static_assert(!std::is_nothrow_constructible<DT, std::tuple<int&>>::value, "");
+#if __cplusplus > 202002L
+  // See the note about P2321R2 above.
+  static_assert(std::is_nothrow_constructible<DT, const std::tuple<int&&>>::value, "");
+#else
   static_assert(!std::is_nothrow_constructible<DT, const std::tuple<int&&>>::value, "");
+#endif
 
   static_assert(!std::is_nothrow_constructible<DT, D>::value, "");
   static_assert(std::is_nothrow_constructible<DT,const D>::value, "");
@@ -565,7 +596,12 @@ namespace NothrowCopyThrowMoveThrowCopyConversionNothrowMoveConversion
   static_assert(std::is_nothrow_constructible<DT, DT&>::value, "");
   static_assert(std::is_nothrow_constructible<DT, const DT &>::value, "");
   static_assert(std::is_nothrow_constructible<DT, std::tuple<D&>>::value, "");
+#if __cplusplus > 202002L
+  // See note about P2321R2 above.
+  static_assert(!std::is_nothrow_constructible<DT, const std::tuple<D&&>>::value, "");
+#else
   static_assert(std::is_nothrow_constructible<DT, const std::tuple<D&&>>::value, "");
+#endif
 
   static_assert(!test_trait::is_nothrow_convertible<DT,DT>::value,"");
   static_assert(test_trait::is_nothrow_convertible<const DT,DT>::value,"");
@@ -884,7 +920,12 @@ namespace ThrowMoveNothrowConversion
   static_assert(std::is_nothrow_constructible<DT, IT&>::value, "");
   static_assert(std::is_nothrow_constructible<DT, const IT &>::value, "");
   static_assert(std::is_nothrow_constructible<DT, std::tuple<int&>>::value, "");
+#if __cplusplus > 202002L
+  // See the note about P2321R2 above.
+  static_assert(!std::is_nothrow_constructible<DT, const std::tuple<int&&>>::value, "");
+#else
   static_assert(std::is_nothrow_constructible<DT, const std::tuple<int&&>>::value, "");
+#endif
 
   static_assert(test_trait::is_nothrow_convertible<DT,DT>::value,"");
   static_assert(test_trait::is_nothrow_convertible<D,DT>::value,"");

                 reply	other threads:[~2022-08-24 20:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220824203938.055BA3858C33@sourceware.org \
    --to=ppalka@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).