From: Jonathan Wakely Date: Mon, 2 Sep 2019 11:10:04 +0000 (+0100) Subject: PR libstdc++/91308 fix constraints on unique_ptr assignment X-Git-Tag: releases/gcc-7.5.0~185 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=40358976bafcdcf85dd169f9da64412967f2760d;p=thirdparty%2Fgcc.git PR libstdc++/91308 fix constraints on unique_ptr assignment * testsuite/20_util/unique_ptr/assign/48635_neg.cc: Replace dg-error with dg-prune-output for enable_if failure. * testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc: Add dg-prune-output for enable_if failure. Backport from mainline 2019-07-31 Jonathan Wakely PR libstdc++/91308 * include/bits/unique_ptr.h (unique_ptr::__safe_conversion_up): Remove constraints on deleter that should only apply to the constructor. (unique_ptr::__safe_conversion_up): Likewise. (unique_ptr::unique_ptr(unique_ptr&&)): Restore constraints on deleter here. * testsuite/20_util/unique_ptr/assign/91308.cc: New test. From-SVN: r275311 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 5ea3acf1f0ac..e72eb882bf21 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,21 @@ +2019-09-02 Jonathan Wakely + + * testsuite/20_util/unique_ptr/assign/48635_neg.cc: Replace dg-error + with dg-prune-output for enable_if failure. + * testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc: Add + dg-prune-output for enable_if failure. + + Backport from mainline + 2019-07-31 Jonathan Wakely + + PR libstdc++/91308 + * include/bits/unique_ptr.h (unique_ptr::__safe_conversion_up): Remove + constraints on deleter that should only apply to the constructor. + (unique_ptr::__safe_conversion_up): Likewise. + (unique_ptr::unique_ptr(unique_ptr&&)): Restore + constraints on deleter here. + * testsuite/20_util/unique_ptr/assign/91308.cc: New test. + 2019-09-02 Jonathan Wakely Backport from mainline diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h index 99cf10ef4ee0..101c706954ba 100644 --- a/libstdc++-v3/include/bits/unique_ptr.h +++ b/libstdc++-v3/include/bits/unique_ptr.h @@ -171,14 +171,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // unique_ptr template using __safe_conversion_up = __and_< - is_convertible::pointer, pointer>, - __not_>, - __or_<__and_, - is_same>, - __and_<__not_>, - is_convertible<_Ep, deleter_type>> - > - >; + is_convertible::pointer, pointer>, + __not_> + >; // Constructors. @@ -419,16 +414,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // helper template for detecting a safe conversion from another // unique_ptr template, - typename _Up_element_type = typename _Up_up::element_type> + typename _UPtr = unique_ptr<_Up, _Ep>, + typename _UP_pointer = typename _UPtr::pointer, + typename _UP_element_type = typename _UPtr::element_type> using __safe_conversion_up = __and_< is_array<_Up>, is_same, - is_same, - is_convertible<_Up_element_type(*)[], element_type(*)[]>, - __or_<__and_, is_same>, - __and_<__not_>, - is_convertible<_Ep, deleter_type>>> + is_same<_UP_pointer, _UP_element_type*>, + is_convertible<_UP_element_type(*)[], element_type(*)[]> >; // helper template for detecting a safe conversion from a raw pointer @@ -513,8 +506,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typename = _DeleterConstraint<_Up>> constexpr unique_ptr(nullptr_t) noexcept : _M_t() { } - template>> + template, + typename conditional::value, + is_same<_Ep, _Dp>, + is_convertible<_Ep, _Dp>>::type>> unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept : _M_t(__u.release(), std::forward<_Ep>(__u.get_deleter())) { } 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 9000ad98ad8b..120725f8d080 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 @@ -42,10 +42,9 @@ void f() std::unique_ptr ud(nullptr, d); ub = std::move(ud); // { dg-error "no match" } ub2 = ud; // { dg-error "no match" } -// { dg-error "no type" "" { target *-*-* } 301 } std::unique_ptr uba(nullptr, b); std::unique_ptr uda(nullptr, d); uba = std::move(uda); // { dg-error "no match" } -// { dg-error "no type" "" { target *-*-* } 560 } } +// { dg-prune-output "no type" } diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/91308.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/91308.cc new file mode 100644 index 000000000000..6500ea43f02a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/91308.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2019 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-do compile { target c++11 } } + +#include + +struct D1 +{ + void operator()(int* p) const noexcept { } +}; + +struct D2 : D1 +{ + D2& operator=(D1&&) noexcept { return *this; } +}; + +void +test01() +{ + std::unique_ptr d1; + std::unique_ptr d2; + d2 = std::move(d1); +} + +void +test02() +{ + std::unique_ptr d1; + std::unique_ptr d2; + d2 = std::move(d1); +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc index 8d29c91fd3a4..489ee3efd88e 100644 --- a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc @@ -39,7 +39,7 @@ test07() std::unique_ptr cA3(p); // { dg-error "no matching function" } std::unique_ptr vA3(p); // { dg-error "no matching function" } std::unique_ptr cvA3(p); // { dg-error "no matching function" } - // { dg-error "no type" "" { target *-*-* } 467 } + // { dg-prune-output "no type" } } template