public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Define feature-test macro for std::enable_shared_from_this
@ 2016-08-03 19:11 Jonathan Wakely
  2016-08-04 12:33 ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2016-08-03 19:11 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 290 bytes --]

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.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1484 bytes --]

commit 3a75677f2b6f2b3d2b01138c82bce5c051859e94
Author: Jonathan Wakely <jwakely@redhat.com>
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 <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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Define feature-test macro for std::enable_shared_from_this
  2016-08-03 19:11 [PATCH] Define feature-test macro for std::enable_shared_from_this Jonathan Wakely
@ 2016-08-04 12:33 ` Jonathan Wakely
  2016-08-05 13:57   ` Jonathan Wakely
  2016-08-31 16:57   ` Jonathan Wakely
  0 siblings, 2 replies; 4+ messages in thread
From: Jonathan Wakely @ 2016-08-04 12:33 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 677 bytes --]

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.



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 2904 bytes --]

commit 7c1f28db94c3cb1a28dba4efd0c648bc6c6bb329
Author: Jonathan Wakely <jwakely@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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Define feature-test macro for std::enable_shared_from_this
  2016-08-04 12:33 ` Jonathan Wakely
@ 2016-08-05 13:57   ` Jonathan Wakely
  2016-08-31 16:57   ` Jonathan Wakely
  1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2016-08-05 13:57 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 740 bytes --]

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.


[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 843 bytes --]

commit bdf5a745f3f98517fc0efe3f5daef9da0b8b53c7
Author: Jonathan Wakely <jwakely@redhat.com>
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++</link>.
 	P0033R1
 	</link>
       </entry>
-      <entry align="center"> 6.1 </entry>
+      <entry align="center"> 7 </entry>
       <entry><code>__cpp_lib_enable_shared_from_this >= 201603</code></entry>
     </row>
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Define feature-test macro for std::enable_shared_from_this
  2016-08-04 12:33 ` Jonathan Wakely
  2016-08-05 13:57   ` Jonathan Wakely
@ 2016-08-31 16:57   ` Jonathan Wakely
  1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2016-08-31 16:57 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1400 bytes --]

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

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.


[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 1945 bytes --]

commit 18184a85f843290d16a88d527d7339df26aec98b
Author: Jonathan Wakely <jwakely@redhat.com>
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 0000000..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
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+
+#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> { };
+
+void
+test01()
+{
+  std::shared_ptr<X> sp(new X);
+  auto wp1 = sp->weak_from_this();
+  std::weak_ptr<X> wp2 = sp;
+
+  std::owner_less<> less;
+  VERIFY( !less(wp1, wp2) && !less(wp2, wp1) );
+  VERIFY( !less(wp1, wp2) && !less(wp2, wp1) );
+}
+
+int
+main()
+{
+  test01();
+}

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-08-31 16:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-03 19:11 [PATCH] Define feature-test macro for std::enable_shared_from_this Jonathan Wakely
2016-08-04 12:33 ` Jonathan Wakely
2016-08-05 13:57   ` Jonathan Wakely
2016-08-31 16:57   ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).