]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add noexcept to shared_ptr owner comparisons (LWG 2873)
authorJonathan Wakely <jwakely@redhat.com>
Mon, 4 Sep 2017 17:08:51 +0000 (18:08 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 4 Sep 2017 17:08:51 +0000 (18:08 +0100)
Backport from mainline
2017-06-05  Jonathan Wakely  <jwakely@redhat.com>

* include/bits/shared_ptr_base.h (__shared_ptr::owner_before)
(__weak_ptr::owner_before, _Sp_owner_less::operator()): Add noexcept
specifiers as per LWG 2873 and LWG 2942.
* testsuite/20_util/owner_less/noexcept.cc: New.
* testsuite/20_util/shared_ptr/observers/owner_before.cc: Test
noexcept guarantees.
* testsuite/20_util/weak_ptr/observers/owner_before.cc: Likewise.

From-SVN: r251677

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/shared_ptr_base.h
libstdc++-v3/testsuite/20_util/owner_less/noexcept.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/shared_ptr/observers/owner_before.cc
libstdc++-v3/testsuite/20_util/weak_ptr/observers/owner_before.cc

index 6ca4a210ede24ddae7f6caf8e0bb7b5e2fde4fc0..1a998a66cf74bf13a4f21ad9f6e98566ca5c3cc1 100644 (file)
@@ -1,5 +1,16 @@
 2017-09-04  Jonathan Wakely  <jwakely@redhat.com>
 
+       Backport from mainline
+       2017-06-05  Jonathan Wakely  <jwakely@redhat.com>
+
+       * include/bits/shared_ptr_base.h (__shared_ptr::owner_before)
+       (__weak_ptr::owner_before, _Sp_owner_less::operator()): Add noexcept
+       specifiers as per LWG 2873 and LWG 2942.
+       * testsuite/20_util/owner_less/noexcept.cc: New.
+       * testsuite/20_util/shared_ptr/observers/owner_before.cc: Test
+       noexcept guarantees.
+       * testsuite/20_util/weak_ptr/observers/owner_before.cc: Likewise.
+
        Backport from mainline
        2017-08-31  Jonathan Wakely  <jwakely@redhat.com>
 
index d71df31a0ad2ba7fccdb83e6fa100deb13e49d87..b0ba18a0d67974c4c62a203c3a6602d26eb548f1 100644 (file)
@@ -1079,12 +1079,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       template<typename _Tp1>
        bool
-       owner_before(__shared_ptr<_Tp1, _Lp> const& __rhs) const
+       owner_before(__shared_ptr<_Tp1, _Lp> const& __rhs) const noexcept
        { return _M_refcount._M_less(__rhs._M_refcount); }
 
       template<typename _Tp1>
        bool
-       owner_before(__weak_ptr<_Tp1, _Lp> const& __rhs) const
+       owner_before(__weak_ptr<_Tp1, _Lp> const& __rhs) const noexcept
        { return _M_refcount._M_less(__rhs._M_refcount); }
 
 #if __cpp_rtti
@@ -1441,12 +1441,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       template<typename _Tp1>
        bool
-       owner_before(const __shared_ptr<_Tp1, _Lp>& __rhs) const
+       owner_before(const __shared_ptr<_Tp1, _Lp>& __rhs) const noexcept
        { return _M_refcount._M_less(__rhs._M_refcount); }
 
       template<typename _Tp1>
        bool
-       owner_before(const __weak_ptr<_Tp1, _Lp>& __rhs) const
+       owner_before(const __weak_ptr<_Tp1, _Lp>& __rhs) const noexcept
        { return _M_refcount._M_less(__rhs._M_refcount); }
 
       void
@@ -1488,15 +1488,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct _Sp_owner_less : public binary_function<_Tp, _Tp, bool>
     {
       bool
-      operator()(const _Tp& __lhs, const _Tp& __rhs) const
+      operator()(const _Tp& __lhs, const _Tp& __rhs) const noexcept
       { return __lhs.owner_before(__rhs); }
 
       bool
-      operator()(const _Tp& __lhs, const _Tp1& __rhs) const
+      operator()(const _Tp& __lhs, const _Tp1& __rhs) const noexcept
       { return __lhs.owner_before(__rhs); }
 
       bool
-      operator()(const _Tp1& __lhs, const _Tp& __rhs) const
+      operator()(const _Tp1& __lhs, const _Tp& __rhs) const noexcept
       { return __lhs.owner_before(__rhs); }
     };
 
diff --git a/libstdc++-v3/testsuite/20_util/owner_less/noexcept.cc b/libstdc++-v3/testsuite/20_util/owner_less/noexcept.cc
new file mode 100644 (file)
index 0000000..a1ef34a
--- /dev/null
@@ -0,0 +1,32 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+#include <memory>
+
+const std::shared_ptr<int> si;
+const std::weak_ptr<int> wi;
+const std::owner_less<std::shared_ptr<int>> osi;
+static_assert( noexcept(osi(si, si)), "" );
+static_assert( noexcept(osi(si, wi)), "" );
+static_assert( noexcept(osi(wi, si)), "" );
+const std::owner_less<std::weak_ptr<int>> owi;
+static_assert( noexcept(owi(wi, wi)), "" );
+static_assert( noexcept(owi(si, wi)), "" );
+static_assert( noexcept(owi(wi, si)), "" );
index 11b9b899d7fadb58a62969636f9a5cb3c3968c1a..6bf6a0249c0faf8f3be79aa8b62cca0659366e1d 100644 (file)
@@ -71,6 +71,12 @@ test02()
   VERIFY( !a1.owner_before(w1) && !w1.owner_before(a1) );
   std::weak_ptr<A> w2(a2);
   VERIFY( !b1.owner_before(w2) && !w2.owner_before(b1) );
+
+  static_assert( noexcept(a1.owner_before(a0)), "" );
+  static_assert( noexcept(a1.owner_before(b1)), "" );
+  static_assert( noexcept(b1.owner_before(a1)), "" );
+  static_assert( noexcept(a1.owner_before(w1)), "" );
+  static_assert( noexcept(b1.owner_before(w1)), "" );
 }
 
 // Aliasing
index 4a615ed77b6d3011de079c360d627032d35c9e3b..37d7a6f5a236138dc98f6f879af430a085883593 100644 (file)
@@ -27,7 +27,7 @@ struct B { };
 
 // 20.6.6.3.5 weak_ptr observers [util.smartptr.weak.obs]
 
-int
+void
 test01()
 {
   bool test __attribute__((unused)) = true;
@@ -40,11 +40,14 @@ test01()
   std::shared_ptr<B> p3;
   VERIFY( !p1.owner_before(p3) && !p3.owner_before(p1) );
 
-  return 0;
+  static_assert( noexcept(p1.owner_before(p1)), "" );
+  static_assert( noexcept(p1.owner_before(p2)), "" );
+  static_assert( noexcept(p1.owner_before(p3)), "" );
+  static_assert( noexcept(p2.owner_before(p1)), "" );
 }
 
 
-int
+void
 test02()
 {
   bool test __attribute__((unused)) = true;
@@ -64,8 +67,6 @@ test02()
 
   std::shared_ptr<B> b1(new B);
   VERIFY( w1.owner_before(b1) || b1.owner_before(w1) );
-
-  return 0;
 }
 
 int