From 3e2e197673d9568bb85556da44ce31ebe5a32ab3 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 2 Mar 2010 00:40:28 +0000 Subject: re PR libstdc++/43183 (std::unique_ptr::reset() does not conform to N3035.) 2010-03-02 Jonathan Wakely PR libstdc++/43183 * include/bits/unique_ptr.h (reset): Fix as per working paper. (operator*, operator->, operator[], operator bool, release): Use pointer's null value instead of 0. * testsuite/20_util/unique_ptr/assign/assign_neg.cc: Adjust. * testsuite/20_util/unique_ptr/modifiers/reset_neg.cc: Adjust. * testsuite/20_util/unique_ptr/modifiers/43183.cc: New. From-SVN: r157158 --- libstdc++-v3/ChangeLog | 10 ++++ libstdc++-v3/include/bits/unique_ptr.h | 32 ++++++------- .../20_util/unique_ptr/assign/assign_neg.cc | 4 +- .../20_util/unique_ptr/modifiers/43183.cc | 55 ++++++++++++++++++++++ .../20_util/unique_ptr/modifiers/reset_neg.cc | 2 +- 5 files changed, 83 insertions(+), 20 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/43183.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 0c5e002..a34bb50 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2010-03-02 Jonathan Wakely + + PR libstdc++/43183 + * include/bits/unique_ptr.h (reset): Fix as per working paper. + (operator*, operator->, operator[], operator bool, release): Use + pointer's null value instead of 0. + * testsuite/20_util/unique_ptr/assign/assign_neg.cc: Adjust. + * testsuite/20_util/unique_ptr/modifiers/reset_neg.cc: Adjust. + * testsuite/20_util/unique_ptr/modifiers/43183.cc: New. + 2010-03-01 Paolo Carlini * include/std/iomanip (get_money, put_money): Add in C++0x mode; tidy. diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h index 7134865..974a5a2 100644 --- a/libstdc++-v3/include/bits/unique_ptr.h +++ b/libstdc++-v3/include/bits/unique_ptr.h @@ -152,14 +152,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std) typename std::add_lvalue_reference::type operator*() const { - _GLIBCXX_DEBUG_ASSERT(get() != 0); + _GLIBCXX_DEBUG_ASSERT(get() != pointer()); return *get(); } pointer operator->() const { - _GLIBCXX_DEBUG_ASSERT(get() != 0); + _GLIBCXX_DEBUG_ASSERT(get() != pointer()); return get(); } @@ -178,25 +178,24 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { return std::get<1>(_M_t); } explicit operator bool() const - { return get() == 0 ? false : true; } + { return get() == pointer() ? false : true; } // Modifiers. pointer release() { pointer __p = get(); - std::get<0>(_M_t) = 0; + std::get<0>(_M_t) = pointer(); return __p; } void reset(pointer __p = pointer()) { - if (__p != get()) - { - get_deleter()(get()); - std::get<0>(_M_t) = __p; - } + using std::swap; + swap(std::get<0>(_M_t), __p); + if (__p != pointer()) + get_deleter()(__p); } void @@ -293,7 +292,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) typename std::add_lvalue_reference::type operator[](size_t __i) const { - _GLIBCXX_DEBUG_ASSERT(get() != 0); + _GLIBCXX_DEBUG_ASSERT(get() != pointer()); return get()[__i]; } @@ -312,25 +311,24 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { return std::get<1>(_M_t); } explicit operator bool() const - { return get() == 0 ? false : true; } + { return get() == pointer() ? false : true; } // Modifiers. pointer release() { pointer __p = get(); - std::get<0>(_M_t) = 0; + std::get<0>(_M_t) = pointer(); return __p; } void reset(pointer __p = pointer()) { - if (__p != get()) - { - get_deleter()(get()); - std::get<0>(_M_t) = __p; - } + using std::swap; + swap(std::get<0>(_M_t), __p); + if (__p != pointer()) + get_deleter()(__p); } // DR 821. diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/assign_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/assign_neg.cc index 1813239..0916bf6 100644 --- a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/assign_neg.cc +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/assign_neg.cc @@ -49,7 +49,7 @@ test03() std::unique_ptr p2 = p1; } -// { dg-error "deleted function" "" { target *-*-* } 348 } +// { dg-error "deleted function" "" { target *-*-* } 346 } // { dg-error "used here" "" { target *-*-* } 42 } // { dg-error "no matching" "" { target *-*-* } 48 } // { dg-warning "candidates are" "" { target *-*-* } 115 } @@ -57,5 +57,5 @@ test03() // { dg-warning "note" "" { target *-*-* } 103 } // { dg-warning "note" "" { target *-*-* } 98 } // { dg-warning "note" "" { target *-*-* } 92 } -// { dg-error "deleted function" "" { target *-*-* } 210 } +// { dg-error "deleted function" "" { target *-*-* } 209 } // { dg-error "used here" "" { target *-*-* } 49 } diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/43183.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/43183.cc new file mode 100644 index 0000000..6dcf729 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/43183.cc @@ -0,0 +1,55 @@ +// { dg-options "-std=gnu++0x" } + +// 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.5 unique_ptr modifiers [unique.ptr.single.modifiers] + +#include +#include + +struct D +{ + static int count; + + void operator()(int* p) const + { + ++count; + delete p; + } +}; +int D::count = 0; + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::unique_ptr up; + up.reset(); + VERIFY( D::count == 0 ); + up.reset(new int); + VERIFY( D::count == 0 ); + up.reset(up.get()); + VERIFY( D::count == 1 ); + up.release(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/reset_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/reset_neg.cc index 61b7ae9..f292d65 100644 --- a/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/reset_neg.cc +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/reset_neg.cc @@ -36,4 +36,4 @@ void test01() } // { dg-error "used here" "" { target *-*-* } 35 } -// { dg-error "deleted function" "" { target *-*-* } 338 } +// { dg-error "deleted function" "" { target *-*-* } 336 } -- cgit v1.1