From f21f4463adb78df847273f328ac163461d4d1617 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 3 Aug 2016 20:09:57 +0100 Subject: [PATCH] Define std::shared_ptr::weak_type * 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 | 6 ++++ libstdc++-v3/include/bits/shared_ptr.h | 5 +++ libstdc++-v3/include/bits/shared_ptr_base.h | 4 +++ .../20_util/shared_ptr/cons/43820_neg.cc | 2 +- .../20_util/shared_ptr/cons/void_neg.cc | 2 +- .../shared_ptr/requirements/weak_type.cc | 31 +++++++++++++++++++ 6 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/shared_ptr/requirements/weak_type.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index bec650b78a9..2c23c4baf68 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,11 @@ 2016-08-03 Jonathan Wakely + * 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. diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index 16f78f7968a..483c2bcecd7 100644 --- a/libstdc++-v3/include/bits/shared_ptr.h +++ b/libstdc++-v3/include/bits/shared_ptr.h @@ -97,6 +97,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION = typename enable_if::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 diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index 1474df603b7..93ce9013f30 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -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() { } 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 395094f8bbe..1b3dc1d550b 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 p1(px); // { dg-error "here" } - // { dg-error "incomplete" "" { target *-*-* } 889 } + // { dg-error "incomplete" "" { target *-*-* } 893 } std::shared_ptr p9(ap()); // { dg-error "here" } // { dg-error "incomplete" "" { target *-*-* } 307 } 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 8843ffea429..399d2f08387 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 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 index 00000000000..38f95022dbd --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/requirements/weak_type.cc @@ -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 +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile } + +#include + +using std::shared_ptr; +using std::weak_ptr; +using std::is_same_v; + +static_assert( is_same_v::weak_type, weak_ptr> ); +static_assert( is_same_v::weak_type, weak_ptr> ); + +struct X { }; +static_assert( is_same_v::weak_type, weak_ptr> ); -- 2.30.2