]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR77990 fix unique_ptr for non-copyable deleters
authorJonathan Wakely <jwakely@redhat.com>
Wed, 19 Oct 2016 10:36:24 +0000 (11:36 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 19 Oct 2016 10:36:24 +0000 (11:36 +0100)
PR libstdc++/77990
* include/bits/unique_ptr.h (unique_ptr::unique_ptr(pointer)): Set
pointer member after value-initialization of tuple.
* testsuite/20_util/unique_ptr/assign/48635_neg.cc: Adjust dg-errors.
* testsuite/20_util/unique_ptr/cons/77990.cc: New test.

From-SVN: r241337

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/unique_ptr.h
libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc
libstdc++-v3/testsuite/20_util/unique_ptr/cons/77990.cc [new file with mode: 0644]

index 18b6538350d1d7e118f8f13a482dd5ca4b6e747c..6f4813b9a616f783f944cfee754eeb4c5bfda55f 100644 (file)
@@ -1,3 +1,11 @@
+2016-10-19  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR libstdc++/77990
+       * include/bits/unique_ptr.h (unique_ptr::unique_ptr(pointer)): Set
+       pointer member after value-initialization of tuple.
+       * testsuite/20_util/unique_ptr/assign/48635_neg.cc: Adjust dg-errors.
+       * testsuite/20_util/unique_ptr/cons/77990.cc: New test.
+
 2016-10-17  Jonathan Wakely  <jwakely@redhat.com>
 
        Backport from mainline:
index 59078d7951ebe897dfd6a962a467d451276a0ec5..cee8ca1bf17d6a9dec1a8c1853bac1808cb7e2d6 100644 (file)
@@ -167,9 +167,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        */
       explicit
       unique_ptr(pointer __p) noexcept
-      : _M_t(__p, deleter_type())
-      { static_assert(!is_pointer<deleter_type>::value,
-                    "constructed with null function pointer deleter"); }
+      : _M_t()
+      {
+       std::get<0>(_M_t) = __p;
+       static_assert(!is_pointer<deleter_type>::value,
+                    "constructed with null function pointer deleter");
+      }
 
       /** Takes ownership of a pointer.
        *
index 185f39c093a202dab669b2f3ca1f2a9e29612cba..7c7928274d2d93494a1113b50acda3fad26e62c0 100644 (file)
@@ -41,10 +41,10 @@ void f()
   std::unique_ptr<int, B&> ub(nullptr, b);
   std::unique_ptr<int, D&> ud(nullptr, d);
   ub = std::move(ud);
-// { dg-error "use of deleted function" "" { target *-*-* } 272 }
+// { dg-error "use of deleted function" "" { target *-*-* } 275 }
 
   std::unique_ptr<int[], B&> uba(nullptr, b);
   std::unique_ptr<int[], D&> uda(nullptr, d);
   uba = std::move(uda);
-// { dg-error "use of deleted function" "" { target *-*-* } 517 }
+// { dg-error "use of deleted function" "" { target *-*-* } 520 }
 }
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/77990.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/77990.cc
new file mode 100644 (file)
index 0000000..1acc313
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright (C) 2016 Free Software Foundation, Inc.
+//
+// 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/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+#include <memory>
+
+struct D {
+  D() = default;
+  D(const D&) = delete;
+  void operator()(int*);
+};
+std::unique_ptr<int, D> p((int*)nullptr);  // PR libstdc++/77990