On 03/08/16 20:11 +0100, Jonathan Wakely wrote:
Another feature we already support, so just define the macro.
* include/bits/shared_ptr_base.h (__cpp_lib_enable_shared_from_this):
Define feature-test macro.
* testsuite/20_util/enable_shared_from_this/members/reinit.cc: Test
for the macro.
Tested x86_64-linux, committed to trunk.
I realised we don't actually implement the whole feature, because we
don't have the new weak_from_this() members (careless of me to forget
the contents of my own proposal!)
This adds them for C++17, or gnu++1*, and only defines the
feature-test macro when those members are present.
Tested powerpc64-linux, committed to trunk.
commit 7c1f28db94c3cb1a28dba4efd0c648bc6c6bb329
Author: Jonathan Wakely <jwak...@redhat.com>
Date: Thu Aug 4 13:04:14 2016 +0100
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.
diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h
index 483c2bc..747b09a 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<const _Tp>(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<const _Tp>
+ weak_from_this() const
+ { return this->_M_weak_this; }
+#endif
+
private:
template<typename _Tp1>
void
diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h
index 2698ba4..787dc9b 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<const _Tp, _Lp>(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<const _Tp, _Lp>
+ weak_from_this() const
+ { return this->_M_weak_this; }
+#endif
+
private:
template<typename _Tp1>
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 1cf9148..3209f87 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
// <http://www.gnu.org/licenses/>.
-// { dg-options "-std=gnu++11" }
+// { dg-do run { target c++11 } }
#include <memory>
#include <testsuite_hooks.h>
-#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<X> { };
bool