From patchwork Thu Oct 20 10:10:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 78471 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp696605qge; Thu, 20 Oct 2016 03:10:51 -0700 (PDT) X-Received: by 10.98.58.73 with SMTP id h70mr20089781pfa.138.1476958251096; Thu, 20 Oct 2016 03:10:51 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id r4si6512501paq.15.2016.10.20.03.10.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Oct 2016 03:10:51 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-439098-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-439098-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-439098-patch=linaro.org@gcc.gnu.org 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=QW9fYvqfq6hW0mitWbeZ9NVxO4rwdr S98wwmgcQahGbub1Hy2S70E2SCn5c2SNMgPyPEYaZk8MJAeEqaa5DOE7HxaFQzFH pYMJuKOtDaFcY0XWhKy5iB+At/JRWK9sZLqSd8W6h59nEEU6D4P0fuHdB8jIHw/6 fxVbzomUf2CWo= 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=zPJYiDJhLG+/F3v2DDM/V0/U2QQ=; b=s3ij 8hO9BpwlVV4/nIzcnv6GNEhkczGql5v6P5YkcVgLWxs4CKMK3AnO+dfNSDlyQFvh tRVHosGhMH5L8wVT1/2MQsp/FB3SKdF/2SX2vPtQXd3M81wd3Jd+73xW0wK/RuwS fi+gjQSsPr3+a8duIVojXGv7eBOLHHYhO6joSFA= Received: (qmail 29332 invoked by alias); 20 Oct 2016 10:10:34 -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 29305 invoked by uid 89); 20 Oct 2016 10:10:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=expired 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 ESMTP; Thu, 20 Oct 2016 10:10:22 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (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 095C23F15E; Thu, 20 Oct 2016 10:10:21 +0000 (UTC) Received: from localhost (ovpn-116-70.ams2.redhat.com [10.36.116.70]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9KAAK7V012827; Thu, 20 Oct 2016 06:10:20 -0400 Date: Thu, 20 Oct 2016 11:10:19 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Make std::enable_shared_from_this cope with ambiguity Message-ID: <20161020101019.GE2922@redhat.com> References: <20161019201303.GA3478@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20161019201303.GA3478@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.7.0 (2016-08-17) On 19/10/16 21:13 +0100, Jonathan Wakely wrote: > The standard says we have to enable shared_from_this for types with > an accessible and unambiguous std::enable_shared_from_this base > class, and we should be able to do that even if the class also has > an experimental::enable_shared_from_this base class. Now we can. This adds some more checks for that case. Tested x86_64-linux, committed to trunk. commit ad6e844e7d0a30a5cb53044d6147f291f9d70378 Author: Jonathan Wakely Date: Thu Oct 20 01:00:16 2016 +0100 Add more tests for enable_shared_from_this ambiguities * testsuite/20_util/enable_shared_from_this/56383.cc: Add tests for additional ambiguous cases. diff --git a/libstdc++-v3/testsuite/20_util/enable_shared_from_this/56383.cc b/libstdc++-v3/testsuite/20_util/enable_shared_from_this/56383.cc index fb3fa69..9220eaf 100644 --- a/libstdc++-v3/testsuite/20_util/enable_shared_from_this/56383.cc +++ b/libstdc++-v3/testsuite/20_util/enable_shared_from_this/56383.cc @@ -20,37 +20,66 @@ #include #include -struct A : std::enable_shared_from_this +template +bool not_enabled(T& t) { - void* a() { return shared_from_this().get(); } -}; +#if __cpp_lib_enable_shared_from_this >= 201603 + return t.weak_from_this().expired(); +#else + try { + t.shared_from_this(); + return false; + } catch (const std::bad_weak_ptr&) { + return true; + } +#endif +} -struct B : std::enable_shared_from_this -{ -}; - -struct D : A, B -{ -}; +struct A : std::enable_shared_from_this { }; +struct B : std::enable_shared_from_this { }; +struct D : A, B { }; void test01() { - bool test = false; - auto d = std::make_shared(); - try - { - d->a(); - } - catch (const std::bad_weak_ptr&) - { - test = true; - } - VERIFY(test); + VERIFY( not_enabled( static_cast(*d) ) ); + VERIFY( not_enabled( static_cast(*d) ) ); + VERIFY( not_enabled( static_cast(*d) ) ); + VERIFY( not_enabled( static_cast(*d) ) ); +} + +struct E : std::__enable_shared_from_this { }; +struct F : std::__enable_shared_from_this { }; +struct G : E, F { }; + +void test02() +{ + auto g = std::make_shared(); + VERIFY( not_enabled( static_cast(*g) ) ); + VERIFY( not_enabled( static_cast(*g) ) ); + VERIFY( not_enabled( static_cast(*g) ) ); + VERIFY( not_enabled( static_cast(*g) ) ); +} + +struct H : D, G { }; + +void test03() +{ + auto h = std::make_shared(); + VERIFY( not_enabled( static_cast(*h) ) ); + VERIFY( not_enabled( static_cast(*h) ) ); + VERIFY( not_enabled( static_cast(*h) ) ); + VERIFY( not_enabled( static_cast(*h) ) ); + VERIFY( not_enabled( static_cast(*h) ) ); + VERIFY( not_enabled( static_cast(*h) ) ); + VERIFY( not_enabled( static_cast(*h) ) ); + VERIFY( not_enabled( static_cast(*h) ) ); } int main() { test01(); + test02(); + test03(); }