public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r12-1296] libstdc++: Finish implementing LWG 3413 for propagate_const
Date: Tue,  8 Jun 2021 14:01:14 +0000 (GMT)	[thread overview]
Message-ID: <20210608140114.329C9395444C@sourceware.org> (raw)

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

commit r12-1296-gd319517e809ee50496db29e552f86a83a14c837c
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jun 8 14:56:57 2021 +0100

    libstdc++: Finish implementing LWG 3413 for propagate_const
    
    We already have conditional noexcept so this just constrains the
    non-member swap overload.
    
    Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
    
    libstdc++-v3/ChangeLog:
    
            * include/experimental/propagate_const (swap): Constrain.
            * testsuite/experimental/propagate_const/swap/lwg3413.cc: New test.

Diff:
---
 libstdc++-v3/include/experimental/propagate_const  |  8 ++++-
 .../experimental/propagate_const/swap/lwg3413.cc   | 41 ++++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/experimental/propagate_const b/libstdc++-v3/include/experimental/propagate_const
index 0d03c13c5e1..162b4783dd7 100644
--- a/libstdc++-v3/include/experimental/propagate_const
+++ b/libstdc++-v3/include/experimental/propagate_const
@@ -113,6 +113,7 @@ inline namespace fundamentals_v2
       constexpr propagate_const() = default;
       propagate_const(const propagate_const& __p) = delete;
       constexpr propagate_const(propagate_const&& __p) = default;
+
       template <typename _Up, typename
 		enable_if<__and_<is_constructible<_Tp, _Up&&>,
 				 is_convertible<_Up&&, _Tp>>::value, bool
@@ -120,6 +121,7 @@ inline namespace fundamentals_v2
       constexpr propagate_const(propagate_const<_Up>&& __pu)
 	: _M_t(std::move(get_underlying(__pu)))
       {}
+
       template <typename _Up, typename
 		enable_if<__and_<is_constructible<_Tp, _Up&&>,
 				 __not_<is_convertible<_Up&&, _Tp>>>::value,
@@ -127,6 +129,7 @@ inline namespace fundamentals_v2
       constexpr explicit propagate_const(propagate_const<_Up>&& __pu)
 	: _M_t(std::move(get_underlying(__pu)))
       {}
+
       template <typename _Up, typename
 		enable_if<__and_<is_constructible<_Tp, _Up&&>,
 				 is_convertible<_Up&&, _Tp>,
@@ -136,6 +139,7 @@ inline namespace fundamentals_v2
       constexpr propagate_const(_Up&& __u)
 	: _M_t(std::forward<_Up>(__u))
       {}
+
       template <typename _Up, typename
 		enable_if<__and_<is_constructible<_Tp, _Up&&>,
 				 __not_<is_convertible<_Up&&, _Tp>>,
@@ -399,8 +403,10 @@ inline namespace fundamentals_v2
     }
 
   // [propagate_const.algorithms], specialized algorithms
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 3413. propagate_const's swap [...] needs to be constrained and use a trait
   template <typename _Tp>
-    constexpr void
+    constexpr enable_if_t<__is_swappable<_Tp>::value, void>
     swap(propagate_const<_Tp>& __pt, propagate_const<_Tp>& __pt2)
       noexcept(__is_nothrow_swappable<_Tp>::value)
     {
diff --git a/libstdc++-v3/testsuite/experimental/propagate_const/swap/lwg3413.cc b/libstdc++-v3/testsuite/experimental/propagate_const/swap/lwg3413.cc
new file mode 100644
index 00000000000..8dc13cfebdd
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/propagate_const/swap/lwg3413.cc
@@ -0,0 +1,41 @@
+// { dg-do compile { target c++14 } }
+
+// LWG 3413
+// propagate_const's swap's noexcept specification needs to be constrained
+// and use a trait
+
+#include <experimental/propagate_const>
+
+using std::experimental::propagate_const;
+
+propagate_const<int*> i;
+static_assert( noexcept(i.swap(i)), "member swap is noexcept" );
+static_assert( noexcept(swap(i, i)), "non-member swap is noexcept" );
+
+struct P
+{
+  int i = 0;
+  int& operator*() const;
+};
+
+void swap(P&, P&) noexcept(false);
+
+propagate_const<P> p;
+static_assert( ! noexcept(p.swap(p)), "member swap is conditionally noexcept" );
+static_assert( ! noexcept(swap(p, p)), "non-member swap is conditionally noexcept" );
+
+// std::is_swappable not available for -std=c++14
+#if __cplusplus > 201402L || !defined(__STRICT_ANSI__)
+struct Q
+{
+  int i = 0;
+  int& operator*() const;
+
+  Q& operator=(Q&&) = delete;
+};
+
+static_assert( ! std::is_swappable<Q>::value, "" );
+
+static_assert( ! std::is_swappable<propagate_const<Q>>::value,
+	       "non-member swap is constrained" );
+#endif


                 reply	other threads:[~2021-06-08 14:01 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=20210608140114.329C9395444C@sourceware.org \
    --to=redi@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).