From: Jonathan Wakely Date: Thu, 4 Aug 2016 12:33:10 +0000 (+0100) Subject: Define std::enable_shared_from_this::weak_from_this X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9a8e528cf1e5aa1a7e7fa09716a3b5b87b56dc93;p=gcc.git Define std::enable_shared_from_this::weak_from_this * testsuite/20_util/enable_shared_from_this/members/reinit.cc: Use effective target not dg-options. Move check for feature-test macro to: * testsuite/20_util/enable_shared_from_this/members/weak_from_this.cc: New test. From-SVN: r239121 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b124d757ff3..bf22550a6e3 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,10 @@ 2016-08-04 Jonathan Wakely + * testsuite/20_util/enable_shared_from_this/members/reinit.cc: Use + effective target not dg-options. Move check for feature-test macro to: + * testsuite/20_util/enable_shared_from_this/members/weak_from_this.cc: + New test. + * include/std/functional (_Unwrap): Rename to __inv_unwrap. (__invfwd): Adjust. (__invoke_impl): Remove unused template parameters. diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index 483c2bcecd7..747b09a2155 100644 --- a/libstdc++-v3/include/bits/shared_ptr.h +++ b/libstdc++-v3/include/bits/shared_ptr.h @@ -586,6 +586,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION shared_from_this() const { return shared_ptr(this->_M_weak_this); } +#if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11 +#define __cpp_lib_enable_shared_from_this 201603 + weak_ptr<_Tp> + weak_from_this() + { return this->_M_weak_this; } + + weak_ptr + weak_from_this() const + { return this->_M_weak_this; } +#endif + private: template void diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index 2698ba453a6..787dc9b8658 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -1472,7 +1472,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void _M_assign(_Tp* __ptr, const __shared_count<_Lp>& __refcount) noexcept { -#define __cpp_lib_enable_shared_from_this 201603 if (use_count() == 0) { _M_ptr = __ptr; @@ -1557,6 +1556,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION shared_from_this() const { return __shared_ptr(this->_M_weak_this); } +#if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11 + __weak_ptr<_Tp, _Lp> + weak_from_this() + { return this->_M_weak_this; } + + __weak_ptr + weak_from_this() const + { return this->_M_weak_this; } +#endif + private: template void diff --git a/libstdc++-v3/testsuite/20_util/enable_shared_from_this/members/reinit.cc b/libstdc++-v3/testsuite/20_util/enable_shared_from_this/members/reinit.cc index 1cf914805a4..3209f87026a 100644 --- a/libstdc++-v3/testsuite/20_util/enable_shared_from_this/members/reinit.cc +++ b/libstdc++-v3/testsuite/20_util/enable_shared_from_this/members/reinit.cc @@ -15,15 +15,11 @@ // with this library; see the file COPYING3. If not see // . -// { dg-options "-std=gnu++11" } +// { dg-do run { target c++11 } } #include #include -#if __cpp_lib_enable_shared_from_this < 201603 -# error "__cpp_lib_enable_shared_from_this < 201603" -#endif - struct X : public std::enable_shared_from_this { }; bool