OSDN Git Service

2010-03-02 Jonathan Wakely <jwakely.gcc@gmail.com>
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 2 Mar 2010 00:40:28 +0000 (00:40 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 2 Mar 2010 00:40:28 +0000 (00:40 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@157158 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/unique_ptr.h
libstdc++-v3/testsuite/20_util/unique_ptr/assign/assign_neg.cc
libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/43183.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/reset_neg.cc

index 0c5e002..a34bb50 100644 (file)
@@ -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.
index 7134865..974a5a2 100644 (file)
@@ -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.
index 1813239..0916bf6 100644 (file)
@@ -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 }
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 (file)
index 0000000..6dcf729
--- /dev/null
@@ -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;
+}
index 61b7ae9..f292d65 100644 (file)
@@ -36,4 +36,4 @@ void test01()
 }
 
 // { dg-error "used here" "" { target *-*-* } 35 } 
-// { dg-error "deleted function" "" { target *-*-* } 338 }
+// { dg-error "deleted function" "" { target *-*-* } 336 }