public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [patch] Constructing std::shared_ptr from an empty std::unique_ptr
Date: Wed, 13 May 2015 16:46:00 -0000	[thread overview]
Message-ID: <20150513164229.GN30202@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 151 bytes --]

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4383.html#2415

Voted in to the WP in Lenexa.

Tested powerpc64le-linux, committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 3258 bytes --]

commit 87937e036ae87944f7ac2b26d8ae17fe81525c4f
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed May 13 15:54:45 2015 +0100

    	* include/bits/shared_ptr_base.h (__shared_count(unique_ptr&&)): Check
    	for nullptr (LWG 2415).
    	* testsuite/20_util/shared_ptr/cons/unique_ptr_deleter.cc: Test
    	construction from empty unique_ptr.
    	* testsuite/20_util/shared_ptr/cons/43820_neg.cc: Adjust dg-error.
    	* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.

diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h
index 8c3af12..081df87 100644
--- a/libstdc++-v3/include/bits/shared_ptr_base.h
+++ b/libstdc++-v3/include/bits/shared_ptr_base.h
@@ -632,6 +632,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
         explicit
 	__shared_count(std::unique_ptr<_Tp, _Del>&& __r) : _M_pi(0)
 	{
+	  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+	  // 2415. Inconsistency between unique_ptr and shared_ptr
+	  if (__r.get() == nullptr)
+	    return;
+
 	  using _Ptr = typename unique_ptr<_Tp, _Del>::pointer;
 	  using _Del2 = typename conditional<is_reference<_Del>::value,
 	      reference_wrapper<typename remove_reference<_Del>::type>,
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc
index 97cc139..6255522 100644
--- a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc
@@ -32,7 +32,7 @@ void test01()
 {
   X* px = 0;
   std::shared_ptr<X> p1(px);   // { dg-error "here" }
-  // { dg-error "incomplete" "" { target *-*-* } 886 }
+  // { dg-error "incomplete" "" { target *-*-* } 891 }
 
   std::shared_ptr<X> p9(ap());  // { dg-error "here" }
   // { dg-error "incomplete" "" { target *-*-* } 307 }
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter.cc
index 67bf577..e010977 100644
--- a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter.cc
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter.cc
@@ -34,7 +34,7 @@ int D::count = 0;
 // 20.7.12.2.1 shared_ptr constructors [util.smartptr.shared.const]
 
 // Construction from unique_ptr
-int
+void
 test01()
 {
   bool test __attribute__((unused)) = true;
@@ -47,13 +47,25 @@ test01()
       VERIFY( sp.use_count() == 1 );
   }
   VERIFY( D::count == 1 );
+}
 
-  return 0;
+void
+test02()
+{
+  bool test __attribute__((unused)) = true;
+
+  D::count = 0;
+  std::unique_ptr<A, D> up;
+  {
+    std::shared_ptr<A> sp = std::move(up);
+  }
+  VERIFY( D::count == 0 ); // LWG 2415
 }
 
 int
 main()
 {
   test01();
+  test02();
   return 0;
 }
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/void_neg.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/void_neg.cc
index 2afcd8b..3f6c4ae 100644
--- a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/void_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/void_neg.cc
@@ -25,5 +25,5 @@
 void test01()
 {
   std::shared_ptr<void> p((void*)nullptr);   // { dg-error "here" }
-  // { dg-error "incomplete" "" { target *-*-* } 885 }
+  // { dg-error "incomplete" "" { target *-*-* } 890 }
 }

                 reply	other threads:[~2015-05-13 16:43 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=20150513164229.GN30202@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@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).