From patchwork Tue Dec 14 22:13:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 75574 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]) by ozlabs.org (Postfix) with SMTP id C10A6B6EED for ; Wed, 15 Dec 2010 09:13:55 +1100 (EST) Received: (qmail 20755 invoked by alias); 14 Dec 2010 22:13:51 -0000 Received: (qmail 20738 invoked by uid 22791); 14 Dec 2010 22:13:49 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-wy0-f175.google.com (HELO mail-wy0-f175.google.com) (74.125.82.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 14 Dec 2010 22:13:42 +0000 Received: by wyb40 with SMTP id 40so981135wyb.20 for ; Tue, 14 Dec 2010 14:13:39 -0800 (PST) MIME-Version: 1.0 Received: by 10.216.46.135 with SMTP id r7mr5456621web.21.1292364819546; Tue, 14 Dec 2010 14:13:39 -0800 (PST) Received: by 10.216.160.131 with HTTP; Tue, 14 Dec 2010 14:13:39 -0800 (PST) Date: Tue, 14 Dec 2010 22:13:39 +0000 Message-ID: Subject: [v3] fix libstdc++/46910 From: Jonathan Wakely To: "libstdc++" , gcc-patches 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 2010-12-14 Jonathan Wakely PR libstdc++/46910 * include/bits/shared_ptr_base.h (_Sp_counted_deleter): Do not derive from _Sp_counted_ptr. * testsuite/20_util/shared_ptr/cons/46910.cc: New. * testsuite/20_util/shared_ptr/cons/43820.cc: Adjust. * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust. tested x86_64-linux, committed to trunk Index: include/bits/shared_ptr_base.h =================================================================== --- include/bits/shared_ptr_base.h (revision 167789) +++ include/bits/shared_ptr_base.h (working copy) @@ -318,7 +318,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // Support for custom deleter and/or allocator template - class _Sp_counted_deleter : public _Sp_counted_ptr<_Ptr, _Lp> + class _Sp_counted_deleter : public _Sp_counted_base<_Lp> { typedef typename _Alloc::template rebind<_Sp_counted_deleter>::other _My_alloc_type; @@ -334,21 +334,18 @@ _GLIBCXX_BEGIN_NAMESPACE(std) : _My_alloc_type(__a), _M_del(__d) { } }; - protected: - typedef _Sp_counted_ptr<_Ptr, _Lp> _Base_type; - public: // __d(__p) must not throw. _Sp_counted_deleter(_Ptr __p, _Deleter __d) - : _Base_type(__p), _M_del(__d, _Alloc()) { } + : _M_ptr(__p), _M_del(__d, _Alloc()) { } // __d(__p) must not throw. _Sp_counted_deleter(_Ptr __p, _Deleter __d, const _Alloc& __a) - : _Base_type(__p), _M_del(__d, __a) { } + : _M_ptr(__p), _M_del(__d, __a) { } virtual void _M_dispose() // nothrow - { _M_del._M_del(_Base_type::_M_ptr); } + { _M_del._M_del(_M_ptr); } virtual void _M_destroy() // nothrow @@ -369,6 +366,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) } protected: + _Ptr _M_ptr; // copy constructor must not throw _My_Deleter _M_del; // copy constructor must not throw }; @@ -397,7 +395,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { void* __p = &_M_storage; ::new (__p) _Tp(); // might throw - _Base_type::_Base_type::_M_ptr = static_cast<_Tp*>(__p); + _Base_type::_M_ptr = static_cast<_Tp*>(__p); } template @@ -407,7 +405,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { void* __p = &_M_storage; ::new (__p) _Tp(std::forward<_Args>(__args)...); // might throw - _Base_type::_Base_type::_M_ptr = static_cast<_Tp*>(__p); + _Base_type::_M_ptr = static_cast<_Tp*>(__p); } // Override because the allocator needs to know the dynamic type Index: testsuite/20_util/shared_ptr/cons/46910.cc =================================================================== --- testsuite/20_util/shared_ptr/cons/46910.cc (revision 0) +++ testsuite/20_util/shared_ptr/cons/46910.cc (revision 0) @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2010 Free Software Foundation +// +// 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 +// . + +// 20.9.10.2 Class template shared_ptr [util.smartptr.shared] + +#include +#include + +// 20.9.10.2.1 shared_ptr constructors [util.smartptr.shared.const] + +struct deleter; + +class A +{ + ~A() = default; + friend struct deleter; +}; + +struct deleter +{ + void operator()(A* a) const; +}; + +void +test01() +{ + std::shared_ptr p(new A, deleter()); +} + Index: testsuite/20_util/shared_ptr/cons/43820.cc =================================================================== --- testsuite/20_util/shared_ptr/cons/43820.cc (revision 167789) +++ testsuite/20_util/shared_ptr/cons/43820.cc (working copy) @@ -32,9 +32,9 @@ void test01() { X* px = 0; std::shared_ptr p1(px); // { dg-error "here" } - // { dg-error "incomplete" "" { target *-*-* } 765 } + // { dg-error "incomplete" "" { target *-*-* } 763 } std::shared_ptr p9(ap()); // { dg-error "here" } - // { dg-error "incomplete" "" { target *-*-* } 857 } + // { dg-error "incomplete" "" { target *-*-* } 855 } } Index: testsuite/20_util/weak_ptr/comparison/cmp_neg.cc =================================================================== --- testsuite/20_util/weak_ptr/comparison/cmp_neg.cc (revision 167789) +++ testsuite/20_util/weak_ptr/comparison/cmp_neg.cc (working copy) @@ -43,7 +43,7 @@ main() } // { dg-warning "note" "" { target *-*-* } 352 } -// { dg-warning "note" "" { target *-*-* } 1085 } +// { dg-warning "note" "" { target *-*-* } 1083 } // { dg-warning "note" "" { target *-*-* } 465 } // { dg-warning "note" "" { target *-*-* } 585 } // { dg-warning "note" "" { target *-*-* } 1048 }