summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite
diff options
context:
space:
mode:
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2017-07-25 18:05:19 +0000
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2017-07-25 18:05:19 +0000
commit9c4eac5526d5c4532add5a378ed797f1d653a191 (patch)
tree028f432e3e21f5787095856ec2904df37f43fe85 /libstdc++-v3/testsuite
parentb96c487cf86fbf6505df72915db6c0bd75da26a6 (diff)
Add noexcept to shared_ptr owner comparisons (LWG 2873)
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-7-branch@250540 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r--libstdc++-v3/testsuite/20_util/owner_less/noexcept.cc40
-rw-r--r--libstdc++-v3/testsuite/20_util/shared_ptr/observers/owner_before.cc6
-rw-r--r--libstdc++-v3/testsuite/20_util/weak_ptr/observers/owner_before.cc11
3 files changed, 52 insertions, 5 deletions
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
index 000000000000..25c9afde8e15
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/owner_less/noexcept.cc
@@ -0,0 +1,40 @@
+// 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-do compile { target c++11 } }
+
+#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)), "" );
+const std::shared_ptr<long> sl;
+const std::weak_ptr<char> wc;
+const std::owner_less<void> ov;
+static_assert( noexcept(ov(si, si)), "" );
+static_assert( noexcept(ov(si, sl)), "" );
+static_assert( noexcept(ov(sl, si)), "" );
+static_assert( noexcept(ov(si, wc)), "" );
+static_assert( noexcept(ov(wc, si)), "" );
+static_assert( noexcept(ov(wc, wi)), "" );
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/observers/owner_before.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/observers/owner_before.cc
index a913f618d1d0..f7e53f1d4324 100644
--- a/libstdc++-v3/testsuite/20_util/shared_ptr/observers/owner_before.cc
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/observers/owner_before.cc
@@ -67,6 +67,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
diff --git a/libstdc++-v3/testsuite/20_util/weak_ptr/observers/owner_before.cc b/libstdc++-v3/testsuite/20_util/weak_ptr/observers/owner_before.cc
index c3a952f0cd73..45f84dbf2276 100644
--- a/libstdc++-v3/testsuite/20_util/weak_ptr/observers/owner_before.cc
+++ b/libstdc++-v3/testsuite/20_util/weak_ptr/observers/owner_before.cc
@@ -27,7 +27,7 @@ struct B { };
// 20.6.6.3.5 weak_ptr observers [util.smartptr.weak.obs]
-int
+void
test01()
{
// test empty weak_ptrs compare equivalent
@@ -38,11 +38,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()
{
std::shared_ptr<A> a0;
@@ -60,8 +63,6 @@ test02()
std::shared_ptr<B> b1(new B);
VERIFY( w1.owner_before(b1) || b1.owner_before(w1) );
-
- return 0;
}
int