From patchwork Wed Aug 11 08:50:45 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 61464 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 E8AFBB6F01 for ; Wed, 11 Aug 2010 18:51:12 +1000 (EST) Received: (qmail 15156 invoked by alias); 11 Aug 2010 08:51:05 -0000 Received: (qmail 15112 invoked by uid 22791); 11 Aug 2010 08:51:00 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from vsmtp2.tin.it (HELO vsmtp2.tin.it) (212.216.176.222) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 11 Aug 2010 08:50:49 +0000 Received: from [192.168.0.4] (79.52.212.149) by vsmtp2.tin.it (8.0.022) id 49F5BE4226603AA9; Wed, 11 Aug 2010 10:50:46 +0200 Message-ID: <4C626465.8010707@oracle.com> Date: Wed, 11 Aug 2010 10:50:45 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.11) Gecko/20100714 SUSE/3.0.6 Thunderbird/3.0.6 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] libstdc++/42925 X-IsSubscribed: yes 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 Hi, tested x86_64-linux, committed to mainline. Paolo. //////////////////////// 2010-08-11 Paolo Carlini PR libstdc++/42925 * include/bits/unique_ptr.h (operator==(const unique_ptr<>&, nullptr_t), operator==(nullptr_t, const unique_ptr<>&), operator!=(const unique_ptr<>&, nullptr_t), operator!=(nullptr_t, const unique_ptr<>&)): Add. * include/bits/shared_ptr_base.h (operator==(const __shared_ptr<>&, nullptr_t), operator==(nullptr_t, const __shared_ptr<>&), operator!=(const __shared_ptr<>&, nullptr_t), operator!=(nullptr_t, const __shared_ptr<>&)): Likewise. * include/bits/shared_ptr.h (operator==(const shared_ptr<>&, nullptr_t), operator==(nullptr_t, const shared_ptr<>&), operator!=(const shared_ptr<>&, nullptr_t), operator!=(nullptr_t, const shared_ptr<>&)): Likewise. * testsuite/20_util/unique_ptr/comparison/42925.cc: New. * testsuite/20_util/shared_ptr/comparison/42925.cc: Likewise. * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust dg-error line numbers. Index: include/bits/unique_ptr.h =================================================================== --- include/bits/unique_ptr.h (revision 163092) +++ include/bits/unique_ptr.h (working copy) @@ -101,7 +101,7 @@ public: typedef typename _Pointer::type pointer; typedef _Tp element_type; - typedef _Dp deleter_type; + typedef _Dp deleter_type; // Constructors. unique_ptr() @@ -432,6 +432,16 @@ const unique_ptr<_Up, _Ep>& __y) { return __x.get() == __y.get(); } + template + inline bool + operator==(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) + { return __x.get() == nullptr; } + + template + inline bool + operator==(nullptr_t, const unique_ptr<_Tp, _Dp>& __y) + { return nullptr == __y.get(); } + template inline bool @@ -439,6 +449,16 @@ const unique_ptr<_Up, _Ep>& __y) { return !(__x.get() == __y.get()); } + template + inline bool + operator!=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) + { return __x.get() != nullptr; } + + template + inline bool + operator!=(nullptr_t, const unique_ptr<_Tp, _Dp>& __y) + { return nullptr != __y.get(); } + template inline bool Index: include/bits/shared_ptr_base.h =================================================================== --- include/bits/shared_ptr_base.h (revision 163091) +++ include/bits/shared_ptr_base.h (working copy) @@ -851,12 +851,32 @@ const __shared_ptr<_Tp2, _Lp>& __b) { return __a.get() == __b.get(); } + template + inline bool + operator==(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) + { return __a.get() == nullptr; } + + template + inline bool + operator==(nullptr_t, const __shared_ptr<_Tp, _Lp>& __b) + { return nullptr == __b.get(); } + template inline bool operator!=(const __shared_ptr<_Tp1, _Lp>& __a, const __shared_ptr<_Tp2, _Lp>& __b) { return __a.get() != __b.get(); } + template + inline bool + operator!=(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) + { return __a.get() != nullptr; } + + template + inline bool + operator!=(nullptr_t, const __shared_ptr<_Tp, _Lp>& __b) + { return nullptr != __b.get(); } + template inline bool operator<(const __shared_ptr<_Tp1, _Lp>& __a, Index: include/bits/shared_ptr.h =================================================================== --- include/bits/shared_ptr.h (revision 163091) +++ include/bits/shared_ptr.h (working copy) @@ -317,11 +317,31 @@ operator==(const shared_ptr<_Tp1>& __a, const shared_ptr<_Tp2>& __b) { return __a.get() == __b.get(); } + template + inline bool + operator==(const shared_ptr<_Tp>& __a, nullptr_t) + { return __a.get() == nullptr; } + + template + inline bool + operator==(nullptr_t, const shared_ptr<_Tp>& __b) + { return nullptr == __b.get(); } + template inline bool operator!=(const shared_ptr<_Tp1>& __a, const shared_ptr<_Tp2>& __b) { return __a.get() != __b.get(); } + template + inline bool + operator!=(const shared_ptr<_Tp>& __a, nullptr_t) + { return __a.get() != nullptr; } + + template + inline bool + operator!=(nullptr_t, const shared_ptr<_Tp>& __b) + { return nullptr != __b.get(); } + template inline bool operator<(const shared_ptr<_Tp1>& __a, const shared_ptr<_Tp2>& __b) Index: testsuite/20_util/unique_ptr/comparison/42925.cc =================================================================== --- testsuite/20_util/unique_ptr/comparison/42925.cc (revision 0) +++ testsuite/20_util/unique_ptr/comparison/42925.cc (revision 0) @@ -0,0 +1,37 @@ +// { 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 Class template unique_ptr [unique.ptr] + +#include + +// libstdc++/42925 (also see GB 99) +void test01() +{ + std::unique_ptr ptr; + if (ptr == 0) + { } + if (0 == ptr) + { } + if (ptr != 0) + { } + if (0 != ptr) + { } +} Index: testsuite/20_util/shared_ptr/comparison/42925.cc =================================================================== --- testsuite/20_util/shared_ptr/comparison/42925.cc (revision 0) +++ testsuite/20_util/shared_ptr/comparison/42925.cc (revision 0) @@ -0,0 +1,37 @@ +// { 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.11.2 Class template shared_ptr [util.smartptr.shared] + +#include + +// libstdc++/42925 (also see GB 99) +void test01() +{ + std::shared_ptr ptr; + if (ptr == 0) + { } + if (0 == ptr) + { } + if (ptr != 0) + { } + if (0 != ptr) + { } +} Index: testsuite/20_util/weak_ptr/comparison/cmp_neg.cc =================================================================== --- testsuite/20_util/weak_ptr/comparison/cmp_neg.cc (revision 163091) +++ testsuite/20_util/weak_ptr/comparison/cmp_neg.cc (working copy) @@ -41,9 +41,9 @@ return 0; } -// { dg-warning "note" "" { target *-*-* } 327 } -// { dg-warning "note" "" { target *-*-* } 446 } -// { dg-warning "note" "" { target *-*-* } 863 } +// { dg-warning "note" "" { target *-*-* } 347 } +// { dg-warning "note" "" { target *-*-* } 466 } +// { dg-warning "note" "" { target *-*-* } 883 } // { dg-warning "note" "" { target *-*-* } 580 } // { dg-warning "note" "" { target *-*-* } 1027 } // { dg-warning "note" "" { target *-*-* } 340 }