[gcc/devel/omp/gcc-9] PR libstdc++/91308 fix constraints on unique_ptr assignment
Tobias Burnus
burnus@gcc.gnu.org
Thu Mar 5 14:13:00 GMT 2020
https://gcc.gnu.org/g:0793403db3ea73eaa407df21672dc703b9cb77dc
commit 0793403db3ea73eaa407df21672dc703b9cb77dc
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed Jul 31 20:56:08 2019 +0100
PR libstdc++/91308 fix constraints on unique_ptr assignment
Backport from mainline
2019-07-31 Jonathan Wakely <jwakely@redhat.com>
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<T[], D>::__safe_conversion_up): Likewise.
(unique_ptr<T[], D>::unique_ptr(unique_ptr<U, D>&&)): Restore
constraints on deleter here.
* testsuite/20_util/unique_ptr/assign/91308.cc: New test.
From-SVN: r273947
Diff:
---
libstdc++-v3/ChangeLog | 13 ++++++
libstdc++-v3/include/bits/unique_ptr.h | 30 ++++++--------
.../testsuite/20_util/unique_ptr/assign/91308.cc | 46 ++++++++++++++++++++++
3 files changed, 72 insertions(+), 17 deletions(-)
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index feef1f6..02db697 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,6 +1,19 @@
2019-07-31 Jonathan Wakely <jwakely@redhat.com>
Backport from mainline
+ 2019-07-31 Jonathan Wakely <jwakely@redhat.com>
+
+ 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<T[], D>::__safe_conversion_up): Likewise.
+ (unique_ptr<T[], D>::unique_ptr(unique_ptr<U, D>&&)): Restore
+ constraints on deleter here.
+ * testsuite/20_util/unique_ptr/assign/91308.cc: New test.
+
+2019-07-31 Jonathan Wakely <jwakely@redhat.com>
+
+ Backport from mainline
2019-07-29 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/51333
diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h
index 963e4eb..d812974 100644
--- a/libstdc++-v3/include/bits/unique_ptr.h
+++ b/libstdc++-v3/include/bits/unique_ptr.h
@@ -179,14 +179,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// unique_ptr
template<typename _Up, typename _Ep>
using __safe_conversion_up = __and_<
- is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>,
- __not_<is_array<_Up>>,
- __or_<__and_<is_reference<deleter_type>,
- is_same<deleter_type, _Ep>>,
- __and_<__not_<is_reference<deleter_type>>,
- is_convertible<_Ep, deleter_type>>
- >
- >;
+ is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>,
+ __not_<is_array<_Up>>
+ >;
public:
// Constructors.
@@ -442,16 +437,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// helper template for detecting a safe conversion from another
// unique_ptr
template<typename _Up, typename _Ep,
- typename _Up_up = unique_ptr<_Up, _Ep>,
- 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<pointer, element_type*>,
- is_same<typename _Up_up::pointer, _Up_element_type*>,
- is_convertible<_Up_element_type(*)[], element_type(*)[]>,
- __or_<__and_<is_reference<deleter_type>, is_same<deleter_type, _Ep>>,
- __and_<__not_<is_reference<deleter_type>>,
- 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
@@ -541,8 +534,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
: _M_t()
{ }
- template<typename _Up, typename _Ep,
- typename = _Require<__safe_conversion_up<_Up, _Ep>>>
+ template<typename _Up, typename _Ep, typename = _Require<
+ __safe_conversion_up<_Up, _Ep>,
+ typename conditional<is_reference<_Dp>::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/91308.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/91308.cc
new file mode 100644
index 0000000..6500ea4
--- /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
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do compile { target c++11 } }
+
+#include <memory>
+
+struct D1
+{
+ void operator()(int* p) const noexcept { }
+};
+
+struct D2 : D1
+{
+ D2& operator=(D1&&) noexcept { return *this; }
+};
+
+void
+test01()
+{
+ std::unique_ptr<int, D1> d1;
+ std::unique_ptr<int, D2> d2;
+ d2 = std::move(d1);
+}
+
+void
+test02()
+{
+ std::unique_ptr<int[], D1> d1;
+ std::unique_ptr<int[], D2> d2;
+ d2 = std::move(d1);
+}
More information about the Libstdc++-cvs
mailing list