This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.

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();
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]