Commit 23df8534 by Jonathan Wakely Committed by Jonathan Wakely

functional (_Require): Move to ...

	* include/std/functional (_Require): Move to ...
	* include/std/type_traits (_Require): ... here.
	* include/bits/shared_ptr_base.h (__shared_count::_S_create_from_up):
	Handle unique_ptr for arrays or with custom pointer types.
	(__shared_ptr::__shared_ptr(unique_ptr<_Tp1, _Del>&&): Likewise.
	* include/bits/unique_ptr.h (unique_ptr<_Tp[], _Dp>): Use
	_Dp::pointer if defined. Implement proposed resolution of LWG 2118.
	* testsuite/20_util/shared_ptr/cons/unique_ptr_array.cc: New.
	* testsuite/20_util/unique_ptr/assign/cv_qual.cc: New.
	* testsuite/20_util/unique_ptr/cons/array_convertible_neg.cc: New.
	* testsuite/20_util/unique_ptr/cons/convertible_neg.cc: New.
	* testsuite/20_util/unique_ptr/cons/cv_qual.cc: New.
	* testsuite/20_util/unique_ptr/modifiers/cv_qual.cc: New.
	* testsuite/20_util/unique_ptr/requirements/pointer_type_array.cc: New.
	* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Adjust comments.
	* testsuite/20_util/unique_ptr/cons/pointer_array_convertible_neg.cc:
	Likewise.
	* testsuite/20_util/unique_ptr/requirements/pointer_type.cc: Likewise.
	* testsuite/20_util/bind/ref_neg.cc: Adjust dg-error line number.
	* testsuite/20_util/declval/requirements/1_neg.cc: Likewise.
	* testsuite/20_util/default_delete/48631_neg.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/43820_neg.cc: Likewise.
	* testsuite/20_util/unique_ptr/assign/48635_neg.cc: Likewise.
	* testsuite/20_util/unique_ptr/modifiers/reset_neg.cc: Adjust
	dg-error text.
	* testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc: Use
	different instantiations so static_assert fails for each.

From-SVN: r194651
parent d89da9db
2012-12-20 Jonathan Wakely <jwakely.gcc@gmail.com> 2012-12-20 Jonathan Wakely <jwakely.gcc@gmail.com>
* include/std/functional (_Require): Move to ...
* include/std/type_traits (_Require): ... here.
* include/bits/shared_ptr_base.h (__shared_count::_S_create_from_up):
Handle unique_ptr for arrays or with custom pointer types.
(__shared_ptr::__shared_ptr(unique_ptr<_Tp1, _Del>&&): Likewise.
* include/bits/unique_ptr.h (unique_ptr<_Tp[], _Dp>): Use
_Dp::pointer if defined. Implement proposed resolution of LWG 2118.
* testsuite/20_util/shared_ptr/cons/unique_ptr_array.cc: New.
* testsuite/20_util/unique_ptr/assign/cv_qual.cc: New.
* testsuite/20_util/unique_ptr/cons/array_convertible_neg.cc: New.
* testsuite/20_util/unique_ptr/cons/convertible_neg.cc: New.
* testsuite/20_util/unique_ptr/cons/cv_qual.cc: New.
* testsuite/20_util/unique_ptr/modifiers/cv_qual.cc: New.
* testsuite/20_util/unique_ptr/requirements/pointer_type_array.cc: New.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Adjust comments.
* testsuite/20_util/unique_ptr/cons/pointer_array_convertible_neg.cc:
Likewise.
* testsuite/20_util/unique_ptr/requirements/pointer_type.cc: Likewise.
* testsuite/20_util/bind/ref_neg.cc: Adjust dg-error line number.
* testsuite/20_util/declval/requirements/1_neg.cc: Likewise.
* testsuite/20_util/default_delete/48631_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/43820_neg.cc: Likewise.
* testsuite/20_util/unique_ptr/assign/48635_neg.cc: Likewise.
* testsuite/20_util/unique_ptr/modifiers/reset_neg.cc: Adjust
dg-error text.
* testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc: Use
different instantiations so static_assert fails for each.
2012-12-20 Jonathan Wakely <jwakely.gcc@gmail.com>
PR libstdc++/55741 PR libstdc++/55741
* acinclude.m4 (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Check for Sleep. * acinclude.m4 (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Check for Sleep.
* config.h.in: Regenerate. * config.h.in: Regenerate.
......
...@@ -616,7 +616,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -616,7 +616,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_S_create_from_up(std::unique_ptr<_Tp, _Del>&& __r, _S_create_from_up(std::unique_ptr<_Tp, _Del>&& __r,
typename std::enable_if<!std::is_reference<_Del>::value>::type* = 0) typename std::enable_if<!std::is_reference<_Del>::value>::type* = 0)
{ {
return new _Sp_counted_deleter<_Tp*, _Del, std::allocator<void>, typedef typename unique_ptr<_Tp, _Del>::pointer _Ptr;
return new _Sp_counted_deleter<_Ptr, _Del, std::allocator<void>,
_Lp>(__r.get(), __r.get_deleter()); _Lp>(__r.get(), __r.get_deleter());
} }
...@@ -625,9 +626,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -625,9 +626,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_S_create_from_up(std::unique_ptr<_Tp, _Del>&& __r, _S_create_from_up(std::unique_ptr<_Tp, _Del>&& __r,
typename std::enable_if<std::is_reference<_Del>::value>::type* = 0) typename std::enable_if<std::is_reference<_Del>::value>::type* = 0)
{ {
typedef typename unique_ptr<_Tp, _Del>::pointer _Ptr;
typedef typename std::remove_reference<_Del>::type _Del1; typedef typename std::remove_reference<_Del>::type _Del1;
typedef std::reference_wrapper<_Del1> _Del2; typedef std::reference_wrapper<_Del1> _Del2;
return new _Sp_counted_deleter<_Tp*, _Del2, std::allocator<void>, return new _Sp_counted_deleter<_Ptr, _Del2, std::allocator<void>,
_Lp>(__r.get(), std::ref(__r.get_deleter())); _Lp>(__r.get(), std::ref(__r.get_deleter()));
} }
...@@ -846,7 +848,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -846,7 +848,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
: _M_ptr(__r.get()), _M_refcount() : _M_ptr(__r.get()), _M_refcount()
{ {
__glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
_Tp1* __tmp = __r.get(); auto __tmp = std::__addressof(*__r.get());
_M_refcount = __shared_count<_Lp>(std::move(__r)); _M_refcount = __shared_count<_Lp>(std::move(__r));
__enable_shared_from_this_helper(_M_refcount, __tmp, __tmp); __enable_shared_from_this_helper(_M_refcount, __tmp, __tmp);
} }
......
...@@ -501,9 +501,6 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) ...@@ -501,9 +501,6 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type)
// @} group functors // @} group functors
template<typename... _Cond>
using _Require = typename enable_if<__and_<_Cond...>::value>::type;
template<typename... _Types> template<typename... _Types>
struct _Pack : integral_constant<size_t, sizeof...(_Types)> struct _Pack : integral_constant<size_t, sizeof...(_Types)>
{ }; { };
......
...@@ -1771,6 +1771,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -1771,6 +1771,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct enable_if<true, _Tp> struct enable_if<true, _Tp>
{ typedef _Tp type; }; { typedef _Tp type; };
template<typename... _Cond>
using _Require = typename enable_if<__and_<_Cond...>::value>::type;
// Primary template. // Primary template.
/// Define a member typedef @c type to one of two argument types. /// Define a member typedef @c type to one of two argument types.
......
...@@ -30,10 +30,10 @@ void test01() ...@@ -30,10 +30,10 @@ void test01()
{ {
const int dummy = 0; const int dummy = 0;
std::bind(&inc, _1)(0); // { dg-error "no match" } std::bind(&inc, _1)(0); // { dg-error "no match" }
// { dg-error "rvalue|const" "" { target *-*-* } 1349 } // { dg-error "rvalue|const" "" { target *-*-* } 1346 }
// { dg-error "rvalue|const" "" { target *-*-* } 1363 } // { dg-error "rvalue|const" "" { target *-*-* } 1360 }
// { dg-error "rvalue|const" "" { target *-*-* } 1377 } // { dg-error "rvalue|const" "" { target *-*-* } 1374 }
// { dg-error "rvalue|const" "" { target *-*-* } 1391 } // { dg-error "rvalue|const" "" { target *-*-* } 1388 }
std::bind(&inc, std::ref(dummy))(); // { dg-error "no match" } std::bind(&inc, std::ref(dummy))(); // { dg-error "no match" }
} }
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
// with this library; see the file COPYING3. If not see // with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
// { dg-error "static assertion failed" "" { target *-*-* } 1869 } // { dg-error "static assertion failed" "" { target *-*-* } 1871 }
#include <utility> #include <utility>
......
...@@ -27,4 +27,4 @@ struct D : B { }; ...@@ -27,4 +27,4 @@ struct D : B { };
D d; D d;
std::default_delete<B[]> db; std::default_delete<B[]> db;
typedef decltype(db(&d)) type; // { dg-error "use of deleted function" } typedef decltype(db(&d)) type; // { dg-error "use of deleted function" }
// { dg-error "declared here" "" { target *-*-* } 87 } // { dg-error "declared here" "" { target *-*-* } 104 }
...@@ -32,7 +32,7 @@ void test01() ...@@ -32,7 +32,7 @@ void test01()
{ {
X* px = 0; X* px = 0;
std::shared_ptr<X> p1(px); // { dg-error "here" } std::shared_ptr<X> p1(px); // { dg-error "here" }
// { dg-error "incomplete" "" { target *-*-* } 769 } // { dg-error "incomplete" "" { target *-*-* } 771 }
std::shared_ptr<X> p9(ap()); // { dg-error "here" } std::shared_ptr<X> p9(ap()); // { dg-error "here" }
// { dg-error "incomplete" "" { target *-*-* } 307 } // { dg-error "incomplete" "" { target *-*-* } 307 }
......
// { dg-options "-std=gnu++0x" } // { dg-options "-std=gnu++11" }
// Copyright (C) 2008, 2009 Free Software Foundation // Copyright (C) 2008-2012 Free Software Foundation
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -17,14 +17,14 @@ ...@@ -17,14 +17,14 @@
// with this library; see the file COPYING3. If not see // with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
// 20.7.12.2 Template class shared_ptr [util.smartptr.shared] // 20.7.2.2 Class template shared_ptr [util.smartptr.shared]
#include <memory> #include <memory>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
struct A { }; struct A { };
// 20.7.12.2.1 shared_ptr constructors [util.smartptr.shared.const] // 20.7.2.2.1 shared_ptr constructors [util.smartptr.shared.const]
// Construction from unique_ptr // Construction from unique_ptr
int int
......
// { dg-options "-std=gnu++11" }
// Copyright (C) 2012 Free Software Foundation
//
// 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/>.
// 20.7.2.2 Class template shared_ptr [util.smartptr.shared]
#include <memory>
#include <testsuite_hooks.h>
int destroyed = 0;
struct A : std::enable_shared_from_this<A>
{
~A() { ++destroyed; }
};
// 20.7.2.2.1 shared_ptr constructors [util.smartptr.shared.const]
// Construction from unique_ptr<A[]>
int
test01()
{
bool test __attribute__((unused)) = true;
std::unique_ptr<A[]> up(new A[2]);
std::shared_ptr<A> sp(std::move(up));
VERIFY( up.get() == 0 );
VERIFY( sp.get() != 0 );
VERIFY( sp.use_count() == 1 );
VERIFY( sp->shared_from_this() != nullptr );
sp.reset();
VERIFY( destroyed == 2 );
return 0;
}
int
main()
{
test01();
return 0;
}
...@@ -41,10 +41,10 @@ void f() ...@@ -41,10 +41,10 @@ void f()
std::unique_ptr<int, B&> ub(nullptr, b); std::unique_ptr<int, B&> ub(nullptr, b);
std::unique_ptr<int, D&> ud(nullptr, d); std::unique_ptr<int, D&> ud(nullptr, d);
ub = std::move(ud); ub = std::move(ud);
// { dg-error "use of deleted function" "" { target *-*-* } 198 } // { dg-error "use of deleted function" "" { target *-*-* } 206 }
std::unique_ptr<int[], B&> uba(nullptr, b); std::unique_ptr<int[], B&> uba(nullptr, b);
std::unique_ptr<int[], D&> uda(nullptr, d); std::unique_ptr<int[], D&> uda(nullptr, d);
uba = std::move(uda); uba = std::move(uda);
// { dg-error "use of deleted function" "" { target *-*-* } 344 } // { dg-error "use of deleted function" "" { target *-*-* } 396 }
} }
// { dg-options "-std=gnu++11" }
// { dg-do compile }
// Copyright (C) 2012 Free Software Foundation
//
// 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/>.
// 20.7.1 Class template unique_ptr [unique.ptr]
#include <memory>
struct A { virtual ~A() = default; };
struct B : A { };
// Assignment from objects with different cv-qualification
void
test01()
{
std::unique_ptr<A> upA;
std::unique_ptr<const A> cA;
cA = std::move(upA);
std::unique_ptr<volatile A> vA;
vA = std::move(upA);
std::unique_ptr<const volatile A> cvA;
cvA = std::move(upA);
}
void
test02()
{
std::unique_ptr<B> upB;
std::unique_ptr<const A> cA;
cA = std::move(upB);
std::unique_ptr<volatile A> vA;
vA = std::move(upB);
std::unique_ptr<const volatile A> cvA;
cvA = std::move(upB);
}
void
test03()
{
std::unique_ptr<A[]> upA;
std::unique_ptr<const A[]> cA;
cA = std::move(upA);
std::unique_ptr<volatile A[]> vA;
vA = std::move(upA);
std::unique_ptr<const volatile A[]> cvA;
cvA = std::move(upA);
}
struct A_pointer { operator A*() const { return nullptr; } };
template<typename T>
struct deleter
{
deleter() = default;
template<typename U>
deleter(const deleter<U>) { }
typedef T pointer;
void operator()(T) const { }
};
void
test04()
{
// Allow conversions from user-defined pointer-like types
std::unique_ptr<B[], deleter<A_pointer>> p;
std::unique_ptr<A[], deleter<A*>> upA;
upA = std::move(p);
}
// { dg-do compile }
// { dg-options "-std=gnu++11" }
// Copyright (C) 2012 Free Software Foundation
//
// 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/>.
#include <memory>
struct A
{
};
struct B : A
{
virtual ~B() { }
};
// 20.7.1.3 unique_ptr for array objects [unique.ptr.runtime]
struct D
{
template<typename T>
void operator()(const T* p) const { delete[] p; }
};
// Conversion from different type of unique_ptr<T[], D>
void
test01()
{
std::unique_ptr<B[], D> b(new B[1]);
std::unique_ptr<A[], D> a(std::move(b)); //{ dg-error "no matching function" }
a = std::move(b); //{ dg-error "no match" }
}
// Conversion from non-array form of unique_ptr
void
test02()
{
std::unique_ptr<A> nonarray(new A);
std::unique_ptr<A[]> array(std::move(nonarray)); //{ dg-error "no matching function" }
array = std::move(nonarray); //{ dg-error "no match" }
}
// { dg-prune-output "include" }
// { dg-do compile }
// { dg-options "-std=gnu++11" }
// Copyright (C) 2012 Free Software Foundation
//
// 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/>.
#include <memory>
struct A
{
};
// 20.7.1.3 unique_ptr for array objects [unique.ptr.runtime]
// Conversion to non-array form of unique_ptr
void
test01()
{
std::unique_ptr<A[]> array(new A[1]);
std::unique_ptr<A> nonarray(std::move(array)); //{ dg-error "no matching function" }
nonarray = std::move(array); //{ dg-error "no match" }
}
// { dg-prune-output "include" }
// { dg-options "-std=gnu++11" }
// { dg-do compile }
// Copyright (C) 2012 Free Software Foundation
//
// 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/>.
// 20.7.1 Class template unique_ptr [unique.ptr]
#include <memory>
struct A { virtual ~A() = default; };
struct B : A { };
// Construction from objects with different cv-qualification
void
test01()
{
std::unique_ptr<const A> cA(new A);
std::unique_ptr<volatile A> vA(new A);
std::unique_ptr<const volatile A> cvA(new A);
}
void
test02()
{
std::unique_ptr<const A> cB(new B);
std::unique_ptr<volatile A> vB(new B);
std::unique_ptr<const volatile A> cvB(new B);
}
void
test03()
{
std::unique_ptr<A> upA;
std::unique_ptr<const A> cA(std::move(upA));
std::unique_ptr<volatile A> vA(std::move(upA));
std::unique_ptr<const volatile A> cvA(std::move(upA));
}
void
test04()
{
std::unique_ptr<B> upB;
std::unique_ptr<const A> cA(std::move(upB));
std::unique_ptr<volatile A> vA(std::move(upB));
std::unique_ptr<const volatile A> cvA(std::move(upB));
}
void
test05()
{
std::unique_ptr<const A[]> cA(new A[1]);
std::unique_ptr<volatile A[]> vA(new A[1]);
std::unique_ptr<const volatile A[]> cvA(new A[1]);
}
void
test06()
{
std::unique_ptr<A[]> upA;
std::unique_ptr<const A[]> cA(std::move(upA));
std::unique_ptr<volatile A[]> vA(std::move(upA));
std::unique_ptr<const volatile A[]> cvA(std::move(upA));
}
struct A_pointer { operator A*() const { return nullptr; } };
void
test07()
{
// Allow conversions from user-defined pointer-like types
A_pointer p;
std::unique_ptr<A[]> upA(p);
std::unique_ptr<const A[]> cA(p);
std::unique_ptr<volatile A[]> vA(p);
std::unique_ptr<const volatile A[]> cvA(p);
}
template<typename T>
struct deleter
{
deleter() = default;
template<typename U>
deleter(const deleter<U>) { }
typedef T pointer;
void operator()(T) const { }
};
void
test08()
{
// Allow conversions from user-defined pointer-like types
std::unique_ptr<B[], deleter<A_pointer>> p;
std::unique_ptr<A[], deleter<A*>> upA(std::move(p));
}
// { dg-do compile } // { dg-do compile }
// { dg-options "-std=gnu++0x" } // { dg-options "-std=gnu++11" }
// Copyright (C) 2008, 2009 Free Software Foundation // Copyright (C) 2008-2012 Free Software Foundation
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -29,7 +29,7 @@ struct B : A ...@@ -29,7 +29,7 @@ struct B : A
virtual ~B() { } virtual ~B() { }
}; };
// 20.4.5.1 unique_ptr constructors [unique.ptr.cons] // 20.7.1.3.1 unique_ptr constructors [unique.ptr.runtime.ctor]
// Construction from pointer of derived type // Construction from pointer of derived type
void void
......
// { dg-options "-std=gnu++0x" } // { dg-options "-std=gnu++0x" }
// { dg-do compile } // { dg-do compile }
// Copyright (C) 2010 Free Software Foundation // Copyright (C) 2010-2012 Free Software Foundation
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -18,10 +18,9 @@ ...@@ -18,10 +18,9 @@
// with this library; see the file COPYING3. If not see // with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
// 20.6.11 Template class unique_ptr [unique.ptr] // 20.7.1 Class template unique_ptr [unique.ptr]
#include <memory> #include <memory>
#include <testsuite_hooks.h>
using std::unique_ptr; using std::unique_ptr;
...@@ -30,9 +29,9 @@ using std::unique_ptr; ...@@ -30,9 +29,9 @@ using std::unique_ptr;
void void
test01() test01()
{ {
unique_ptr<int, void(*)(int*)> p1; // { dg-error "here" } unique_ptr<long, void(*)(long*)> p1; // { dg-error "here" }
unique_ptr<int, void(*)(int*)> p2(nullptr); // { dg-error "here" } unique_ptr<short, void(*)(short*)> p2(nullptr); // { dg-error "here" }
unique_ptr<int, void(*)(int*)> p3(new int); // { dg-error "here" } unique_ptr<int, void(*)(int*)> p3(new int); // { dg-error "here" }
} }
...@@ -40,9 +39,9 @@ test01() ...@@ -40,9 +39,9 @@ test01()
void void
test02() test02()
{ {
unique_ptr<int[], void(*)(int*)> p1; // { dg-error "here" } unique_ptr<long[], void(*)(long*)> p1; // { dg-error "here" }
unique_ptr<int[], void(*)(int*)> p2(nullptr); // { dg-error "here" } unique_ptr<short[], void(*)(short*)> p2(nullptr); // { dg-error "here" }
unique_ptr<int[], void(*)(int*)> p3(new int[1]); // { dg-error "here" } unique_ptr<int[], void(*)(int*)> p3(new int[1]); // { dg-error "here" }
} }
......
// { dg-options "-std=gnu++11" }
// { dg-do compile }
// Copyright (C) 2012 Free Software Foundation
//
// 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/>.
// 20.7.1 Class template unique_ptr [unique.ptr]
#include <memory>
struct A { virtual ~A() = default; };
struct B : A { };
// Construction from objects with different cv-qualification
void
test01()
{
std::unique_ptr<const A> cA;
cA.reset(new A);
std::unique_ptr<volatile A> vA;
vA.reset(new A);
std::unique_ptr<const volatile A> cvA;
cvA.reset(new A);
}
void
test02()
{
std::unique_ptr<const A> cB;
cB.reset(new B);
std::unique_ptr<volatile A> vB;
vB.reset(new B);
std::unique_ptr<const volatile A> cvB;
cvB.reset(new B);
}
void
test03()
{
std::unique_ptr<const A[]> cA;
cA.reset(new A[1]);
std::unique_ptr<volatile A[]> vA;
vA.reset(new A[1]);
std::unique_ptr<const volatile A[]> cvA;
cvA.reset(new A[1]);
}
struct A_pointer { operator A*() const { return nullptr; } };
void
test07()
{
// Allow conversions from user-defined pointer-like types
A_pointer p;
std::unique_ptr<A[]> upA;
upA.reset(p);
std::unique_ptr<const A[]> cA;
cA.reset(p);
std::unique_ptr<volatile A[]> vA;
vA.reset(p);
std::unique_ptr<const volatile A[]> cvA;
cvA.reset(p);
}
// { dg-do compile } // { dg-do compile }
// { dg-options "-std=gnu++0x" } // { dg-options "-std=gnu++0x" }
// Copyright (C) 2008, 2009, 2010 Free Software Foundation // Copyright (C) 2008-2012 Free Software Foundation
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -32,7 +32,7 @@ struct B : A ...@@ -32,7 +32,7 @@ struct B : A
void test01() void test01()
{ {
std::unique_ptr<B[]> up; std::unique_ptr<B[]> up;
up.reset(new A[3]); // { dg-error "deleted" } up.reset(new A[3]); // { dg-error "invalid conversion" }
} }
// { dg-prune-output "include" } // { dg-prune-output "include" }
// { dg-do compile } // { dg-do compile }
// { dg-options "-std=gnu++0x" } // { dg-options "-std=gnu++11" }
// Copyright (C) 2010, 2011 Free Software Foundation // Copyright (C) 2010-2012 Free Software Foundation
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -18,10 +18,9 @@ ...@@ -18,10 +18,9 @@
// with this library; see the file COPYING3. If not see // with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
// 20.6.11 Template class unique_ptr [unique.ptr.single] // 20.7.1.2 unique_ptr for single objects [unique.ptr.single]
#include <memory> #include <memory>
#include <testsuite_hooks.h>
struct A struct A
{ {
......
// { dg-do compile }
// { dg-options "-std=gnu++11" }
// Copyright (C) 2010-2012 Free Software Foundation
//
// 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/>.
// 20.7.1.3 unique_ptr for array objects [unique.ptr.runtime]
#include <memory>
struct A
{
void operator()(void*) const { }
};
struct B
{
typedef char* pointer;
void operator()(pointer) const { }
};
int main()
{
typedef std::unique_ptr<int[]> up;
typedef std::unique_ptr<int[], A> upA;
typedef std::unique_ptr<int[], B> upB;
typedef std::unique_ptr<int[], A&> upAr;
typedef std::unique_ptr<int[], B&> upBr;
static_assert( std::is_same< up::pointer, int*>::value, "" );
static_assert( std::is_same< upA::pointer, int*>::value, "" );
static_assert( std::is_same< upB::pointer, char*>::value, "" );
static_assert( std::is_same< upAr::pointer, int*>::value, "" );
static_assert( std::is_same< upBr::pointer, char*>::value, "" );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment