Re: [PATCH] Define feature-test macro for std::enable_shared_from_this

2016-08-31 Thread Jonathan Wakely

On 04/08/16 13:33 +0100, Jonathan Wakely wrote:

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 
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.


I made a mess of this commit, failing to add shared_ptr.h and
shared_ptr_base.h to the ChangeLog, and failing to commit the new
test!

This adds the missing test.

Tested powerpc64le-linux, committed to trunk.

commit 18184a85f843290d16a88d527d7339df26aec98b
Author: Jonathan Wakely 
Date:   Wed Aug 31 14:20:34 2016 +0100

Add test accidentally not added in revision r239121

	* testsuite/20_util/enable_shared_from_this/members/weak_from_this.cc:
	New test.

diff --git a/libstdc++-v3/testsuite/20_util/enable_shared_from_this/members/weak_from_this.cc b/libstdc++-v3/testsuite/20_util/enable_shared_from_this/members/weak_from_this.cc
new file mode 100644
index 000..b5ebb81
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/enable_shared_from_this/members/weak_from_this.cc
@@ -0,0 +1,45 @@
+// Copyright (C) 2015-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" }
+
+#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 { };
+
+void
+test01()
+{
+  std::shared_ptr sp(new X);
+  auto wp1 = sp->weak_from_this();
+  std::weak_ptr wp2 = sp;
+
+  std::owner_less<> less;
+  VERIFY( !less(wp1, wp2) && !less(wp2, wp1) );
+  VERIFY( !less(wp1, wp2) && !less(wp2, wp1) );
+}
+
+int
+main()
+{
+  test01();
+}


Re: [PATCH] Define feature-test macro for std::enable_shared_from_this

2016-08-05 Thread Jonathan Wakely

On 04/08/16 13:33 +0100, Jonathan Wakely wrote:

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.


And this corrects the status in the manual.

commit bdf5a745f3f98517fc0efe3f5daef9da0b8b53c7
Author: Jonathan Wakely 
Date:   Fri Aug 5 14:56:34 2016 +0100

Correct status of __cpp_lib_enable_shared_from_this

	* doc/xml/manual/status_cxx2017.xml: Correct shared_from_this status.
	* doc/html/manual/status.html: Regenerate.

diff --git a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml
index 4d098d1..02aec25 100644
--- a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml
+++ b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml
@@ -261,7 +261,7 @@ Feature-testing recommendations for C++.
 	P0033R1
 	
   
-   6.1 
+   7 
   __cpp_lib_enable_shared_from_this >= 201603
 
 


Re: [PATCH] Define feature-test macro for std::enable_shared_from_this

2016-08-04 Thread Jonathan Wakely

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 
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(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 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(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 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
 // .
 
-// { 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


[PATCH] Define feature-test macro for std::enable_shared_from_this

2016-08-03 Thread Jonathan Wakely

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.

commit 3a75677f2b6f2b3d2b01138c82bce5c051859e94
Author: Jonathan Wakely 
Date:   Wed Aug 3 19:47:53 2016 +0100

Define feature-test macro for std::enable_shared_from_this

* 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.

diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h 
b/libstdc++-v3/include/bits/shared_ptr_base.h
index 93ce901..2698ba4 100644
--- a/libstdc++-v3/include/bits/shared_ptr_base.h
+++ b/libstdc++-v3/include/bits/shared_ptr_base.h
@@ -1472,6 +1472,7 @@ _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;
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 4ce23bc..1cf9148 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
@@ -20,6 +20,10 @@
 #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