From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 41872 invoked by alias); 16 Jun 2017 15:21:16 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 41847 invoked by uid 89); 16 Jun 2017 15:21:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Del, tl, TL, thirdparty 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; Fri, 16 Jun 2017 15:21:13 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 31CC63D952; Fri, 16 Jun 2017 15:21:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 31CC63D952 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jwakely@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 31CC63D952 Received: from localhost (unknown [10.33.36.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id D19AB902DC; Fri, 16 Jun 2017 15:21:11 +0000 (UTC) Date: Fri, 16 Jun 2017 15:21:00 -0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] Add std::get_deleter overload with correct signature Message-ID: <20170616152111.GA11527@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="tThc/1wpZn/ma/RB" Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.8.0 (2017-02-23) X-SW-Source: 2017-06/txt/msg01207.txt.bz2 --tThc/1wpZn/ma/RB Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Content-length: 443 This was found by a third-party testsuite, which complained because we only define get_deleter(const __shared_ptr&) and not the corect signature. * include/bits/shared_ptr.h (get_deleter): Add overload matching standard signature. * include/bits/shared_ptr_base.h (__shared_ptr): Declare new get_deleter overload as a friend. * testsuite/20_util/shared_ptr/misc/get_deleter.cc: New. Tested powerpc64le-linux, committed to trunk. --tThc/1wpZn/ma/RB Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" Content-length: 3665 commit 19e9cbdc902495edd290c749cc76976a9bdec12d Author: Jonathan Wakely Date: Fri Apr 21 14:26:43 2017 +0100 Add std::get_deleter overload with correct signature * include/bits/shared_ptr.h (get_deleter): Add overload matching standard signature. * include/bits/shared_ptr_base.h (__shared_ptr): Declare new get_deleter overload as a friend. * testsuite/20_util/shared_ptr/misc/get_deleter.cc: New. diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index 264e35c..999a034 100644 --- a/libstdc++-v3/include/bits/shared_ptr.h +++ b/libstdc++-v3/include/bits/shared_ptr.h @@ -70,7 +70,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __os; } - /// 20.7.2.2.10 shared_ptr get_deleter template inline _Del* get_deleter(const __shared_ptr<_Tp, _Lp>& __p) noexcept @@ -82,6 +81,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif } + /// 20.7.2.2.10 shared_ptr get_deleter + template + inline _Del* + get_deleter(const shared_ptr<_Tp>& __p) noexcept + { +#if __cpp_rtti + return static_cast<_Del*>(__p._M_get_deleter(typeid(_Del))); +#else + return 0; +#endif + } /** * @brief A smart pointer with reference-counted copy semantics. diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index a07058c..7e6766b 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -1402,6 +1402,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template friend _Del* get_deleter(const __shared_ptr<_Tp1, _Lp1>&) noexcept; + template + friend _Del* get_deleter(const shared_ptr<_Tp1>&) noexcept; + element_type* _M_ptr; // Contained pointer. __shared_count<_Lp> _M_refcount; // Reference counter. }; diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/misc/get_deleter.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/misc/get_deleter.cc new file mode 100644 index 0000000..cb5f4c7 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/misc/get_deleter.cc @@ -0,0 +1,44 @@ +// Copyright (C) 2017 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-do run { target c++11 } } + +#include +#include + +struct Del { + template void operator()(T* p) const noexcept { delete p; } +}; + +Del* (*f1)(const std::shared_ptr&) = std::get_deleter; + +void +test01() +{ + std::shared_ptr p; + VERIFY( std::get_deleter(p) == nullptr ); + p = std::shared_ptr(new int, Del()); + VERIFY( std::get_deleter(p) != nullptr ); + p = std::shared_ptr(new int); + VERIFY( std::get_deleter(p) == nullptr ); +} + +int +main() +{ + test01(); +} --tThc/1wpZn/ma/RB--