Define std::shared_ptr::weak_type
authorJonathan Wakely <jwakely@redhat.com>
Wed, 3 Aug 2016 19:09:57 +0000 (20:09 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 3 Aug 2016 19:09:57 +0000 (20:09 +0100)
* include/bits/shared_ptr.h (shared_ptr::weak_type): Define.
* include/bits/shared_ptr_base.h (__shared_ptr::weak_type): Define.
* testsuite/20_util/shared_ptr/cons/43820_neg.cc: Adjust dg-error.
* testsuite/20_util/shared_ptr/requirements/weak_type.cc: New test.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.

From-SVN: r239093

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/shared_ptr.h
libstdc++-v3/include/bits/shared_ptr_base.h
libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc
libstdc++-v3/testsuite/20_util/shared_ptr/cons/void_neg.cc
libstdc++-v3/testsuite/20_util/shared_ptr/requirements/weak_type.cc [new file with mode: 0644]

index bec650b78a9cad0134995526ca88b3ee3cf9b440..2c23c4baf6873253856028518a47a47cf21091d7 100644 (file)
@@ -1,5 +1,11 @@
 2016-08-03  Jonathan Wakely  <jwakely@redhat.com>
 
+       * include/bits/shared_ptr.h (shared_ptr::weak_type): Define.
+       * include/bits/shared_ptr_base.h (__shared_ptr::weak_type): Define.
+       * testsuite/20_util/shared_ptr/cons/43820_neg.cc: Adjust dg-error.
+       * testsuite/20_util/shared_ptr/requirements/weak_type.cc: New test.
+       * testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
+
        * include/std/utility (as_const): Define.
        * testsuite/20_util/as_const/1.cc: New test.
        * testsuite/20_util/as_const/rvalue_neg.cc: New test.
index 16f78f7968a8e8e5a668c5829982b13fd767e51a..483c2bcecd7750f233fdc9ff4c902ad4fd3beea9 100644 (file)
@@ -97,6 +97,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          = typename enable_if<is_convertible<_Ptr, _Tp*>::value>::type;
 
     public:
+
+#if __cplusplus > 201402L
+# define __cpp_lib_shared_ptr_weak_type 201606
+      using weak_type = weak_ptr<_Tp>;
+#endif
       /**
        *  @brief  Construct an empty %shared_ptr.
        *  @post   use_count()==0 && get()==0
index 1474df603b7f96dbd9fc5cceb3385524ca9fc928..93ce9013f30a313054799489ebf7978fb9d25b43 100644 (file)
@@ -876,6 +876,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     public:
       typedef _Tp   element_type;
 
+#if __cplusplus > 201402L
+      using weak_type = __weak_ptr<_Tp, _Lp>;
+#endif
+
       constexpr __shared_ptr() noexcept
       : _M_ptr(0), _M_refcount()
       { }
index 395094f8bbebc8a01a49c748d67dbdf35250cf57..1b3dc1d550b09de011277f524b61e78434f19ca0 100644 (file)
@@ -32,7 +32,7 @@ void test01()
 {
   X* px = 0;
   std::shared_ptr<X> p1(px);   // { dg-error "here" }
-  // { dg-error "incomplete" "" { target *-*-* } 889 }
+  // { dg-error "incomplete" "" { target *-*-* } 893 }
 
   std::shared_ptr<X> p9(ap());  // { dg-error "here" }
   // { dg-error "incomplete" "" { target *-*-* } 307 }
index 8843ffea429ca235948520ded7389da16ed42a77..399d2f0838778b3330f9f0e93b699d31ba6b650c 100644 (file)
@@ -25,5 +25,5 @@
 void test01()
 {
   std::shared_ptr<void> p((void*)nullptr);   // { dg-error "here" }
-  // { dg-error "incomplete" "" { target *-*-* } 888 }
+  // { dg-error "incomplete" "" { target *-*-* } 892 }
 }
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/requirements/weak_type.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/requirements/weak_type.cc
new file mode 100644 (file)
index 0000000..38f9502
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright (C) 2016 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++17" }
+// { dg-do compile }
+
+#include <memory>
+
+using std::shared_ptr;
+using std::weak_ptr;
+using std::is_same_v;
+
+static_assert( is_same_v<shared_ptr<int>::weak_type, weak_ptr<int>> );
+static_assert( is_same_v<shared_ptr<void>::weak_type, weak_ptr<void>> );
+
+struct X { };
+static_assert( is_same_v<shared_ptr<X>::weak_type, weak_ptr<X>> );