This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] LWG 2996 add rvalue overloads for shared_ptr aliasing and casting
On 24/05/19 11:39 +0100, Jonathan Wakely wrote:
On 24/05/19 11:02 +0200, Christophe Lyon wrote:
Hi Jonathan,
On Thu, 23 May 2019 at 23:40, Jonathan Wakely <jwakely@redhat.com> wrote:
* doc/xml/manual/intro.xml: Document LWG DR 2996 change.
* doc/html/*: Regenerate.
* include/bits/shared_ptr.h (shared_ptr(shared_ptr&&, T*)): Add
rvalue aliasing constructor.
(static_pointer_cast, const_pointer, dynamic_pointer_cast)
(reinterpret_pointer_cast): Add overloads taking rvalues.
* include/bits/shared_ptr_base.h (__shared_ptr(__shared_ptr&&, T*)):
Add rvalue aliasing constructor.
* testsuite/20_util/shared_ptr/casts/1.cc: Change "compile" test to
"run" and check return values as well as types.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/rval.cc: New test.
* testsuite/20_util/shared_ptr/cons/alias-rval.cc: New test.
* testsuite/20_util/shared_ptr/cons/alias.cc: Remove unused return
values.
Tested powerpc64le-linux, committed to trunk.
As you may have noticed, the new test alias-rval.cc fails on arm and
aarch64, and other targets according to gcc-testresults@
Yes, for some reason that test didn't run on the machine I tested on
... not sure why. Fix coming shortly ...
Looks like I only half-finished writing that test, and then it didn't
get run. Here's a correct test, committed to trunk (and definitely
tested this time, on three systems).
commit bd804ab00d8854f7b32969c31126356aed461cfe
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri May 24 13:42:21 2019 +0100
Fix broken shared_ptr test
* testsuite/20_util/shared_ptr/cons/alias-rval.cc: Fix test.
* testsuite/20_util/shared_ptr/cons/alias.cc: Remove unused function.
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/alias-rval.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/alias-rval.cc
index 205587cde66..f0b0d9cf9ff 100644
--- a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/alias-rval.cc
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/alias-rval.cc
@@ -37,8 +37,6 @@ struct B : A
A a;
};
-void deletefunc(A* p) { delete p; }
-
// 20.6.6.2.1 shared_ptr constructors [util.smartptr.shared.const]
// Aliasing constructors
@@ -63,29 +61,33 @@ test01()
void
test02()
{
- std::shared_ptr<A> a(new A);
+ A* ptr = new A;
+ ptr->i = 100;
+ std::shared_ptr<A> a(ptr);
std::shared_ptr<int> i1(std::move(a), &a->i);
VERIFY( i1.use_count() == 1 );
- VERIFY( i1 != nullptr );
+ VERIFY( *i1 == 100 );
VERIFY( a.use_count() == 0 );
VERIFY( a == nullptr );
std::shared_ptr<int> i2(i1);
VERIFY( i2.use_count() == 2 );
- VERIFY( i2.get() == &a->i );
+ VERIFY( i2.get() == &ptr->i );
}
void
test03()
{
std::shared_ptr<B> b1(new B);
+ b1->i = 100;
+ b1->a.i = 200;
std::shared_ptr<B> b2(b1);
std::shared_ptr<A> a1(std::move(b1), b1.get());
- std::shared_ptr<A> a2(b2, &b2->a);
+ std::shared_ptr<A> a2(std::move(b2), &b2->a);
+ VERIFY( a1.use_count() == 2 );
VERIFY( a2.use_count() == 2 );
- VERIFY( a1 != nullptr );
- VERIFY( a2 != nullptr );
- VERIFY( a1 != a2 );
+ VERIFY( a1->i == 100 );
+ VERIFY( a2->i == 200 );
VERIFY( b1.use_count() == 0 );
VERIFY( b2.use_count() == 0 );
VERIFY( b1 == nullptr );
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/alias.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/alias.cc
index 134a05894a2..8dbb7af638c 100644
--- a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/alias.cc
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/alias.cc
@@ -36,8 +36,6 @@ struct B : A
A a;
};
-void deletefunc(A* p) { delete p; }
-
// 20.6.6.2.1 shared_ptr constructors [util.smartptr.shared.const]
// Aliasing constructors