From 0df677c1a36e28d9d7782c79602d0a8e8f65fe11 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 19 Oct 2016 11:36:24 +0100 Subject: [PATCH] PR77990 fix unique_ptr for non-copyable deleters 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 | 8 ++++++ libstdc++-v3/include/bits/unique_ptr.h | 9 ++++-- .../20_util/unique_ptr/assign/48635_neg.cc | 4 +-- .../20_util/unique_ptr/cons/77990.cc | 28 +++++++++++++++++++ 4 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/unique_ptr/cons/77990.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 18b6538350d1..6f4813b9a616 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2016-10-19 Jonathan Wakely + + 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 Backport from mainline: diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h index 59078d7951eb..cee8ca1bf17d 100644 --- a/libstdc++-v3/include/bits/unique_ptr.h +++ b/libstdc++-v3/include/bits/unique_ptr.h @@ -167,9 +167,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ explicit unique_ptr(pointer __p) noexcept - : _M_t(__p, deleter_type()) - { static_assert(!is_pointer::value, - "constructed with null function pointer deleter"); } + : _M_t() + { + std::get<0>(_M_t) = __p; + static_assert(!is_pointer::value, + "constructed with null function pointer deleter"); + } /** Takes ownership of a pointer. * diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc index 185f39c093a2..7c7928274d2d 100644 --- a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc @@ -41,10 +41,10 @@ void f() std::unique_ptr ub(nullptr, b); std::unique_ptr 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 uba(nullptr, b); std::unique_ptr 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 index 000000000000..1acc3135d3b8 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/77990.cc @@ -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 +// . + +// { dg-options "-std=gnu++11" } +// { dg-do compile } + +#include + +struct D { + D() = default; + D(const D&) = delete; + void operator()(int*); +}; +std::unique_ptr p((int*)nullptr); // PR libstdc++/77990 -- 2.47.2