mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-02-25 13:36:01 +08:00
re PR libstdc++/43183 (std::unique_ptr::reset() does not conform to N3035.)
2010-03-02 Jonathan Wakely <jwakely.gcc@gmail.com> 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
This commit is contained in:
parent
f743fd0a4c
commit
3e2e197673
@ -1,3 +1,13 @@
|
||||
2010-03-02 Jonathan Wakely <jwakely.gcc@gmail.com>
|
||||
|
||||
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 <paolo.carlini@oracle.com>
|
||||
|
||||
* include/std/iomanip (get_money, put_money): Add in C++0x mode; tidy.
|
||||
|
@ -152,14 +152,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||
typename std::add_lvalue_reference<element_type>::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<element_type>::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.
|
||||
|
@ -49,7 +49,7 @@ test03()
|
||||
std::unique_ptr<int[2]> 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 }
|
||||
|
55
libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/43183.cc
Normal file
55
libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/43183.cc
Normal file
@ -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
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// 20.9.10.2.5 unique_ptr modifiers [unique.ptr.single.modifiers]
|
||||
|
||||
#include <memory>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
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<int, D> 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;
|
||||
}
|
@ -36,4 +36,4 @@ void test01()
|
||||
}
|
||||
|
||||
// { dg-error "used here" "" { target *-*-* } 35 }
|
||||
// { dg-error "deleted function" "" { target *-*-* } 338 }
|
||||
// { dg-error "deleted function" "" { target *-*-* } 336 }
|
||||
|
Loading…
Reference in New Issue
Block a user