From patchwork Thu Aug 4 12:33:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 655786 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3s4q9d3KNGz9sD5 for ; Thu, 4 Aug 2016 22:33:40 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=XAeEOJ/1; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:references:mime-version:content-type :in-reply-to; q=dns; s=default; b=TfagdFvhGVOgJQnvVviUSlJ3JFBEB5 m7BvdrQKCXOjdD5WTiqhqV1LrMSAOpuIRwaKP0TQsWyC0odYB/+CuFvd/dfPctf0 K+wew7XkO72U+WPRLy2gVR041/oQ5unZJYoH7pTzGCmQ6xc5aBq1kzFJYiN5zXLi Jq4nYPr/jXHwk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:references:mime-version:content-type :in-reply-to; s=default; bh=uZ5UOG57jAc5os+KELhMr3JXPKQ=; b=XAeE OJ/1Pite5xfYY37Du3JR06jR2yxik1uZthVFDDHnhlqNWusjf9sutMb8lSP3eDBQ ZqjTRW6d+hrPMHyy6NdlRJS1dJbmlk74idTD+RZDfFsDq6TSwN37T3D63As10yM4 7kQqXq+3l606Is5FfeFzS3uEkVCcxNR3mTncIko= Received: (qmail 73133 invoked by alias); 4 Aug 2016 12:33:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 73113 invoked by uid 89); 4 Aug 2016 12:33:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=1511, proposal! X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 04 Aug 2016 12:33:10 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0FC9281F03; Thu, 4 Aug 2016 12:33:09 +0000 (UTC) Received: from localhost (ovpn-116-93.ams2.redhat.com [10.36.116.93]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u74CX8Fo004308; Thu, 4 Aug 2016 08:33:08 -0400 Date: Thu, 4 Aug 2016 13:33:07 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Define feature-test macro for std::enable_shared_from_this Message-ID: <20160804123307.GT4264@redhat.com> References: <20160803191125.GA4351@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160803191125.GA4351@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.6.2 (2016-07-01) 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