From: Ville Voutilainen Date: Wed, 4 Jan 2017 13:21:02 +0000 (+0200) Subject: Implement 2801, Default-constructibility of unique_ptr. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1308676957c2f1db7faef7b3b0e594e73ee652e6;p=gcc.git Implement 2801, Default-constructibility of unique_ptr. * include/bits/unique_ptr.h (__uniq_ptr_impl::_DeleterConstraint): New. (unique_ptr::_DeleterConstraint): Likewise. (unique_ptr()): Constrain. (unique_ptr(pointer)): Likewise. (unique_ptr(nullptr_t)): Likewise. (unique_ptr<_Tp[], _Dp>::_DeleterConstraint): New. (unique_ptr<_Tp[], _Dp>::unique_ptr()): Constrain. (unique_ptr<_Tp[], _Dp>::unique_ptr(_Up)): Likewise. (unique_ptr<_Tp[], _Dp>::unique_ptr(nullptr_t)): Likewise. * testsuite/20_util/unique_ptr/assign/48635_neg.cc: Adjust. * testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc: Likewise. * testsuite/20_util/unique_ptr/cons/default.cc: New. * testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc: Adjust. From-SVN: r244054 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 26483dab21a..d0bd7e63fbd 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,20 @@ +2017-01-04 Ville Voutilainen + + Implement 2801, Default-constructibility of unique_ptr. + * include/bits/unique_ptr.h (__uniq_ptr_impl::_DeleterConstraint): New. + (unique_ptr::_DeleterConstraint): Likewise. + (unique_ptr()): Constrain. + (unique_ptr(pointer)): Likewise. + (unique_ptr(nullptr_t)): Likewise. + (unique_ptr<_Tp[], _Dp>::_DeleterConstraint): New. + (unique_ptr<_Tp[], _Dp>::unique_ptr()): Constrain. + (unique_ptr<_Tp[], _Dp>::unique_ptr(_Up)): Likewise. + (unique_ptr<_Tp[], _Dp>::unique_ptr(nullptr_t)): Likewise. + * testsuite/20_util/unique_ptr/assign/48635_neg.cc: Adjust. + * testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc: Likewise. + * testsuite/20_util/unique_ptr/cons/default.cc: New. + * testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc: Adjust. + 2017-01-04 Pauli Nieminen Jonathan Wakely diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h index df3cf92e4fe..a31cd67d6e3 100644 --- a/libstdc++-v3/include/bits/unique_ptr.h +++ b/libstdc++-v3/include/bits/unique_ptr.h @@ -130,6 +130,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; public: + using _DeleterConstraint = enable_if< + __and_<__not_>, + is_default_constructible<_Dp>>::value>; + using pointer = typename _Ptr<_Tp, _Dp>::type; __uniq_ptr_impl() = default; @@ -152,6 +156,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template > class unique_ptr { + template + using _DeleterConstraint = + typename __uniq_ptr_impl<_Tp, _Up>::_DeleterConstraint::type; + __uniq_ptr_impl<_Tp, _Dp> _M_t; public: @@ -175,10 +183,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Constructors. /// Default constructor, creates a unique_ptr that owns nothing. - constexpr unique_ptr() noexcept - : _M_t() - { static_assert(!is_pointer::value, - "constructed with null function pointer deleter"); } + template > + constexpr unique_ptr() noexcept + : _M_t() + { } /** Takes ownership of a pointer. * @@ -186,11 +195,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * The deleter will be value-initialized. */ - explicit - unique_ptr(pointer __p) noexcept - : _M_t(__p) - { static_assert(!is_pointer::value, - "constructed with null function pointer deleter"); } + template > + explicit + unique_ptr(pointer __p) noexcept + : _M_t(__p) + { } /** Takes ownership of a pointer. * @@ -218,7 +228,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION "rvalue deleter bound to reference"); } /// Creates a unique_ptr that owns nothing. - constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { } + template > + constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { } // Move constructors. @@ -384,6 +396,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template class unique_ptr<_Tp[], _Dp> { + template + using _DeleterConstraint = + typename __uniq_ptr_impl<_Tp, _Up>::_DeleterConstraint::type; + __uniq_ptr_impl<_Tp, _Dp> _M_t; template @@ -432,10 +448,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Constructors. /// Default constructor, creates a unique_ptr that owns nothing. - constexpr unique_ptr() noexcept - : _M_t() - { static_assert(!std::is_pointer::value, - "constructed with null function pointer deleter"); } + template > + constexpr unique_ptr() noexcept + : _M_t() + { } /** Takes ownership of a pointer. * @@ -445,13 +462,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * The deleter will be value-initialized. */ template, + typename = typename enable_if< __safe_conversion_raw<_Up>::value, bool>::type> - explicit - unique_ptr(_Up __p) noexcept - : _M_t(__p) - { static_assert(!is_pointer::value, - "constructed with null function pointer deleter"); } + explicit + unique_ptr(_Up __p) noexcept + : _M_t(__p) + { } /** Takes ownership of a pointer. * @@ -491,7 +509,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _M_t(__u.release(), std::forward(__u.get_deleter())) { } /// Creates a unique_ptr that owns nothing. - constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { } + template > + constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { } template>> 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 4f567126555..9000ad98ad8 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,10 @@ 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 *-*-* } 289 } +// { 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 *-*-* } 540 } +// { dg-error "no type" "" { target *-*-* } 560 } } 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 d6b0e554cf2..8d29c91fd3a 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 *-*-* } 448 } + // { dg-error "no type" "" { target *-*-* } 467 } } template diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/default.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/default.cc new file mode 100644 index 00000000000..ceffdcd2b2e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/default.cc @@ -0,0 +1,40 @@ +// { dg-do compile { target c++11 } } + +// 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 +// . + +#include +#include + +static_assert(!std::is_default_constructible&>>::value, ""); +static_assert(!std::is_default_constructible>::value, ""); +static_assert(!std::is_constructible&>, int*>::value, ""); +static_assert(!std::is_constructible, int*>::value, ""); + +static_assert(!std::is_default_constructible&>>::value, ""); +static_assert(!std::is_default_constructible>::value, ""); +static_assert(!std::is_constructible&>, int*>::value, ""); +static_assert(!std::is_constructible, int*>::value, ""); + diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc index bfb01926fff..b4d2d8edbfe 100644 --- a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc @@ -23,26 +23,24 @@ using std::unique_ptr; -// { dg-prune-output "static assertion failed" } - void test01() { - unique_ptr p1; // { dg-error "here" } + unique_ptr p1; // { dg-error "no matching" } - unique_ptr p2(nullptr); // { dg-error "here" } + unique_ptr p2(nullptr); // { dg-error "no matching" } - unique_ptr p3(new int); // { dg-error "here" } + unique_ptr p3(new int); // { dg-error "no matching" } } void test02() { - unique_ptr p1; // { dg-error "here" } + unique_ptr p1; // { dg-error "no matching" } - unique_ptr p2(nullptr); // { dg-error "here" } + unique_ptr p2(nullptr); // { dg-error "no matching" } - unique_ptr p3(new int[1]); // { dg-error "here" } + unique_ptr p3(new int[1]); // { dg-error "no matching" } }