* [PATCH] Add noexcept to shared_ptr owner comparisons (LWG 2873)
@ 2017-06-05 9:34 Jonathan Wakely
2017-09-05 6:30 ` Christophe Lyon
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2017-06-05 9:34 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 531 bytes --]
C++17 requires these to be noexcept, and there's no reason not to do
it for earlier standard modes too.
* 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.
Tested powerpc64le-linux, committed to trunk.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 6601 bytes --]
commit 82f522e382dac837924af829a70c61dd3db0ea94
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon Jun 5 10:12:22 2017 +0100
Add noexcept to shared_ptr owner comparisons (LWG 2873)
* 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.
diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h
index b4a5edf..f0916d0 100644
--- a/libstdc++-v3/include/bits/shared_ptr_base.h
+++ b/libstdc++-v3/include/bits/shared_ptr_base.h
@@ -1309,12 +1309,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); }
protected:
@@ -1697,12 +1697,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
@@ -1747,15 +1747,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); }
};
@@ -1764,7 +1764,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
template<typename _Tp, typename _Up>
auto
- operator()(const _Tp& __lhs, const _Up& __rhs) const
+ operator()(const _Tp& __lhs, const _Up& __rhs) const noexcept
-> decltype(__lhs.owner_before(__rhs))
{ 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
index 0000000..25c9afd
--- /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 a913f618..f7e53f1 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 c3a952f..45f84db 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Add noexcept to shared_ptr owner comparisons (LWG 2873)
2017-06-05 9:34 [PATCH] Add noexcept to shared_ptr owner comparisons (LWG 2873) Jonathan Wakely
@ 2017-09-05 6:30 ` Christophe Lyon
2017-09-05 10:31 ` Jonathan Wakely
0 siblings, 1 reply; 3+ messages in thread
From: Christophe Lyon @ 2017-09-05 6:30 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: libstdc++, gcc-patches
Hi Jonathan
On 5 June 2017 at 11:34, Jonathan Wakely <jwakely@redhat.com> wrote:
> C++17 requires these to be noexcept, and there's no reason not to do
> it for earlier standard modes too.
>
> * 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.
>
> Tested powerpc64le-linux, committed to trunk.
>
I've noticed you have backported this patch to gcc-6-branch (r251673).
The new test testsuite/20_util/owner_less/noexcept.cc fails with:
/libstdc++-v3/testsuite/20_util/owner_less/noexcept.cc:34: error:
aggregate 'const std::owner_less<void> ov' has incomplete type and
cannot be defined
Christophe
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Add noexcept to shared_ptr owner comparisons (LWG 2873)
2017-09-05 6:30 ` Christophe Lyon
@ 2017-09-05 10:31 ` Jonathan Wakely
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2017-09-05 10:31 UTC (permalink / raw)
To: Christophe Lyon; +Cc: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1139 bytes --]
On 05/09/17 08:30 +0200, Christophe Lyon wrote:
>Hi Jonathan
>
>On 5 June 2017 at 11:34, Jonathan Wakely <jwakely@redhat.com> wrote:
>> C++17 requires these to be noexcept, and there's no reason not to do
>> it for earlier standard modes too.
>>
>> * 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.
>>
>> Tested powerpc64le-linux, committed to trunk.
>>
>
>I've noticed you have backported this patch to gcc-6-branch (r251673).
>The new test testsuite/20_util/owner_less/noexcept.cc fails with:
>/libstdc++-v3/testsuite/20_util/owner_less/noexcept.cc:34: error:
>aggregate 'const std::owner_less<void> ov' has incomplete type and
>cannot be defined
Huh, I fixed that in the gcc-5-branch backport, but not gcc-6-branch.
Fixed by this patch.
[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 1525 bytes --]
commit 3c6ae9c30e86263cf764cef946b8783810583079
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Sep 5 10:31:05 2017 +0100
Remove owner_less<void> test that fails on gcc-6-branch
* testsuite/20_util/owner_less/noexcept.cc: Remove owner_less<void>
tests.
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 8a87b7b155a..d88a08f2452 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,8 @@
+2017-09-05 Jonathan Wakely <jwakely@redhat.com>
+
+ * testsuite/20_util/owner_less/noexcept.cc: Remove owner_less<void>
+ tests.
+
2017-09-04 Jonathan Wakely <jwakely@redhat.com>
Backport from mainline
diff --git a/libstdc++-v3/testsuite/20_util/owner_less/noexcept.cc b/libstdc++-v3/testsuite/20_util/owner_less/noexcept.cc
index 25c9afde8e1..fcf5d4f2679 100644
--- a/libstdc++-v3/testsuite/20_util/owner_less/noexcept.cc
+++ b/libstdc++-v3/testsuite/20_util/owner_less/noexcept.cc
@@ -29,12 +29,3 @@ 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)), "" );
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-09-05 10:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-05 9:34 [PATCH] Add noexcept to shared_ptr owner comparisons (LWG 2873) Jonathan Wakely
2017-09-05 6:30 ` Christophe Lyon
2017-09-05 10:31 ` Jonathan Wakely
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).