summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2018-09-11 11:55:49 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2018-09-11 11:55:49 +0100
commit86fc6ec9f366fd95d976c01bfa24c6775537ba62 (patch)
treece28f3d56213828fb0d7b4202d9c1940bcb5feab /libstdc++-v3/testsuite
parent9356a18eb4aa927c9e44245075b82fa0c6001789 (diff)
downloadgcc-86fc6ec9f366fd95d976c01bfa24c6775537ba62.tar.gz
Implement LWG 2905 changes to constrain unique_ptr constructors
LWG DR 2905 says that is_constructible_v<unique_ptr<P, D>, P, D const &> should be false when D is not copy constructible. This commit implements the changes from the DR and simplifies the signatures as per https://github.com/cplusplus/draft/issues/1530 * include/bits/unique_ptr.h (__uniq_ptr_impl): Add assertions to check deleter type. (unique_ptr::unique_ptr(pointer, const deleter_type&)): Add copy constructible constraint. (unique_ptr::unique_ptr(pointer, deleter_type&&)): Disable for deleters of reference type and add move constructible constraint. (unique_ptr::unique_ptr(pointer, remove_reference_t<deleter_type>&&)): Disable for deleters of non-reference type. Define as deleted. (unique_ptr<T[], D>): Likewise. * testsuite/20_util/unique_ptr/assign/48635_neg.cc: Replace dg-error directives with unstable line numbers with dg-prune-output. * testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc: Likewise. * testsuite/20_util/unique_ptr/cons/lwg2905.cc: New test. * testsuite/20_util/unique_ptr/specialized_algorithms/swap_cxx17.cc: Make deleter types invocable. From-SVN: r264206
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r--libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc4
-rw-r--r--libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc2
-rw-r--r--libstdc++-v3/testsuite/20_util/unique_ptr/cons/lwg2905.cc78
-rw-r--r--libstdc++-v3/testsuite/20_util/unique_ptr/specialized_algorithms/swap_cxx17.cc9
4 files changed, 88 insertions, 5 deletions
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 b22d0e123b4..0c8f8b357bb 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<int, D&> ud(nullptr, d);
ub = std::move(ud); // { dg-error "no match" }
ub2 = ud; // { dg-error "no match" }
-// { dg-error "no type" "" { target *-*-* } 307 }
std::unique_ptr<int[], B&> uba(nullptr, b);
std::unique_ptr<int[], D&> uda(nullptr, d);
uba = std::move(uda); // { dg-error "no match" }
-// { dg-error "no type" "" { target *-*-* } 566 }
}
+
+// { dg-prune-output "no type" }
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 c1b1c9efc64..7e820ba129a 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<const A[]> cA3(p); // { dg-error "no matching function" }
std::unique_ptr<volatile A[]> vA3(p); // { dg-error "no matching function" }
std::unique_ptr<const volatile A[]> cvA3(p); // { dg-error "no matching function" }
- // { dg-error "no type" "" { target *-*-* } 473 }
+ // { dg-prune-output "no type" }
}
template<typename T>
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/lwg2905.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/lwg2905.cc
new file mode 100644
index 00000000000..8700630d1b3
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/lwg2905.cc
@@ -0,0 +1,78 @@
+// Copyright (C) 2017 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>
+
+template<typename T, typename D, typename P, typename E>
+constexpr bool check()
+{ return std::is_constructible<std::unique_ptr<T, D>, P, E>::value; }
+
+struct Del { void operator()(void*) const { } };
+
+static_assert( ! check<int, Del&, int*, Del>(), "" );
+static_assert( check<int, Del&, int*, Del&>(), "" );
+static_assert( check<int, const Del&, int*, Del&>(), "" );
+static_assert( ! check<int, Del&, int*, const Del&>(), "" );
+static_assert( check<int, Del, int*, const Del&>(), "" );
+static_assert( check<int, Del, int*, Del>(), "" );
+
+static_assert( ! check<int[], Del&, int*, Del>(), "" );
+static_assert( check<int[], Del&, int*, Del&>(), "" );
+static_assert( check<int[], const Del&, int*, Del&>(), "" );
+static_assert( ! check<int[], Del&, int*, const Del&>(), "" );
+static_assert( check<int[], Del, int*, const Del&>(), "" );
+static_assert( check<int[], Del, int*, Del>(), "" );
+
+struct DelNoCopy {
+ DelNoCopy() = default;
+ DelNoCopy(const DelNoCopy&) = delete;
+ DelNoCopy(DelNoCopy&&) = default;
+ void operator()(void*) const { }
+};
+
+static_assert( ! check<int, DelNoCopy&, int*, DelNoCopy>(), "" );
+static_assert( check<int, DelNoCopy&, int*, DelNoCopy&>(), "" );
+static_assert( check<int, const DelNoCopy&, int*, DelNoCopy&>(), "" );
+static_assert( ! check<int, DelNoCopy&, int*, const DelNoCopy&>(), "" );
+static_assert( ! check<int, DelNoCopy, int*, const DelNoCopy&>(), "" );
+static_assert( check<int, DelNoCopy, int*, DelNoCopy>(), "" );
+
+static_assert( ! check<int[], DelNoCopy&, int*, DelNoCopy>(), "" );
+static_assert( check<int[], DelNoCopy&, int*, DelNoCopy&>(), "" );
+static_assert( check<int[], const DelNoCopy&, int*, DelNoCopy&>(), "" );
+static_assert( ! check<int[], DelNoCopy&, int*, const DelNoCopy&>(), "" );
+static_assert( ! check<int[], DelNoCopy, int*, const DelNoCopy&>(), "" );
+static_assert( check<int[], DelNoCopy, int*, DelNoCopy>(), "" );
+
+struct Base { virtual ~Base() { } };
+struct Derived : Base { };
+
+static_assert( ! check<Base[], Del&, Base*, Del>(), "" );
+static_assert( check<Base[], Del&, Base*, Del&>(), "" );
+static_assert( check<Base[], const Del&, Base*, Del&>(), "" );
+static_assert( ! check<Base[], Del&, Base*, const Del&>(), "" );
+static_assert( check<Base[], Del, Base*, const Del&>(), "" );
+static_assert( check<Base[], Del, Base*, Del>(), "" );
+
+static_assert( ! check<Base[], Del&, Derived*, Del>(), "" );
+static_assert( ! check<Base[], Del&, Derived*, Del&>(), "" );
+static_assert( ! check<Base[], const Del&, Derived*, Del&>(), "" );
+static_assert( ! check<Base[], Del&, Derived*, const Del&>(), "" );
+static_assert( ! check<Base[], Del, Derived*, const Del&>(), "" );
+static_assert( ! check<Base[], Del, Derived*, Del>(), "" );
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/specialized_algorithms/swap_cxx17.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/specialized_algorithms/swap_cxx17.cc
index 298d951d319..604685c1ab1 100644
--- a/libstdc++-v3/testsuite/20_util/unique_ptr/specialized_algorithms/swap_cxx17.cc
+++ b/libstdc++-v3/testsuite/20_util/unique_ptr/specialized_algorithms/swap_cxx17.cc
@@ -21,13 +21,18 @@
#include <memory>
// Not swappable, and unique_ptr not swappable via the generic std::swap.
-struct C { };
+struct C {
+ void operator()(void*) const { }
+};
void swap(C&, C&) = delete;
static_assert( !std::is_swappable_v<std::unique_ptr<int, C>> );
// Not swappable, and unique_ptr not swappable via the generic std::swap.
-struct D { D(D&&) = delete; };
+struct D {
+ D(D&&) = delete;
+ void operator()(void*) const { }
+};
static_assert( !std::is_swappable_v<std::unique_ptr<int, D>> );