From af181c91a9f33ecf355065bcfbfce66c9fb1e111 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 22 Mar 2017 15:58:35 +0000 Subject: [PATCH] Add deduction guides for C++17 (P0433R2, partial) * include/bits/shared_ptr.h (shared_ptr, weak_ptr): Add deduction guides for C++17. * include/bits/std_function.h (function): Likewise. * include/bits/stl_pair.h (pair): Likewise. * include/debug/array (__gnu_debug::array): Likewise. * include/std/array (array): Likewise. * include/std/functional (make_default_searcher) (make_boyer_moore_searcher, make_boyer_moore_horspool_searcher): Remove generator functions. * include/std/tuple (tuple): Add deduction guides. * include/std/valarray (valarray): Likewise. * testsuite/20_util/function_objects/searchers.cc: Adjust to use class template argument deduction instead of generator functions. * testsuite/20_util/function/cons/deduction.cc: New test. * testsuite/20_util/optional/cons/deduction_guide.cc: Rename to ... * testsuite/20_util/optional/cons/deduction.cc: ... here. * testsuite/20_util/pair/cons/deduction.cc: New test. * testsuite/20_util/shared_ptr/cons/deduction.cc: New test. * testsuite/20_util/tuple/cons/deduction.cc: New test. * testsuite/20_util/tuple/element_access/get_neg.cc: Adjust dg-error. * testsuite/20_util/unique_ptr/cons/deduction_neg.cc: New test. * testsuite/20_util/weak_ptr/cons/deduction.cc: New test. * testsuite/23_containers/array/cons/deduction.cc: New test. * testsuite/23_containers/array/cons/deduction_neg.cc: New test. * testsuite/23_containers/array/tuple_interface/get_debug_neg.cc: Adjust dg-error. * testsuite/23_containers/array/tuple_interface/get_neg.cc: Likewise. * testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc: Likewise. * testsuite/26_numerics/valarray/deduction.cc: New test. * testsuite/30_threads/lock_guard/cons/deduction.cc: New test. * testsuite/30_threads/scoped_lock/cons/deduction.cc: New test. * testsuite/30_threads/unique_lock/cons/deduction.cc: New test. From-SVN: r246389 --- libstdc++-v3/ChangeLog | 36 ++++ libstdc++-v3/include/bits/shared_ptr.h | 12 ++ libstdc++-v3/include/bits/std_function.h | 37 ++++ libstdc++-v3/include/bits/stl_pair.h | 4 + libstdc++-v3/include/debug/array | 7 + libstdc++-v3/include/std/array | 7 + libstdc++-v3/include/std/functional | 30 ---- libstdc++-v3/include/std/tuple | 13 ++ libstdc++-v3/include/std/valarray | 5 + .../20_util/function/cons/deduction.cc | 86 +++++++++ .../20_util/function_objects/searchers.cc | 24 +-- .../cons/{deduction_guide.cc => deduction.cc} | 33 ++-- .../testsuite/20_util/pair/cons/deduction.cc | 60 +++++++ .../20_util/shared_ptr/cons/deduction.cc | 45 +++++ .../testsuite/20_util/tuple/cons/deduction.cc | 166 ++++++++++++++++++ .../20_util/tuple/element_access/get_neg.cc | 2 +- .../20_util/unique_ptr/cons/deduction_neg.cc | 36 ++++ .../20_util/weak_ptr/cons/deduction.cc | 39 ++++ .../23_containers/array/cons/deduction.cc | 46 +++++ .../23_containers/array/cons/deduction_neg.cc | 31 ++++ .../array/tuple_interface/get_debug_neg.cc | 6 +- .../array/tuple_interface/get_neg.cc | 6 +- .../tuple_interface/tuple_element_neg.cc | 2 +- .../26_numerics/valarray/deduction.cc | 42 +++++ .../30_threads/lock_guard/cons/deduction.cc | 44 +++++ .../30_threads/scoped_lock/cons/deduction.cc | 53 ++++++ .../30_threads/unique_lock/cons/deduction.cc | 44 +++++ 27 files changed, 852 insertions(+), 64 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/function/cons/deduction.cc rename libstdc++-v3/testsuite/20_util/optional/cons/{deduction_guide.cc => deduction.cc} (61%) create mode 100644 libstdc++-v3/testsuite/20_util/pair/cons/deduction.cc create mode 100644 libstdc++-v3/testsuite/20_util/shared_ptr/cons/deduction.cc create mode 100644 libstdc++-v3/testsuite/20_util/tuple/cons/deduction.cc create mode 100644 libstdc++-v3/testsuite/20_util/unique_ptr/cons/deduction_neg.cc create mode 100644 libstdc++-v3/testsuite/20_util/weak_ptr/cons/deduction.cc create mode 100644 libstdc++-v3/testsuite/23_containers/array/cons/deduction.cc create mode 100644 libstdc++-v3/testsuite/23_containers/array/cons/deduction_neg.cc create mode 100644 libstdc++-v3/testsuite/26_numerics/valarray/deduction.cc create mode 100644 libstdc++-v3/testsuite/30_threads/lock_guard/cons/deduction.cc create mode 100644 libstdc++-v3/testsuite/30_threads/scoped_lock/cons/deduction.cc create mode 100644 libstdc++-v3/testsuite/30_threads/unique_lock/cons/deduction.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6114393e6e4..56a80c7ce62 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,39 @@ +2017-03-22 Jonathan Wakely + + * include/bits/shared_ptr.h (shared_ptr, weak_ptr): Add deduction + guides for C++17. + * include/bits/std_function.h (function): Likewise. + * include/bits/stl_pair.h (pair): Likewise. + * include/debug/array (__gnu_debug::array): Likewise. + * include/std/array (array): Likewise. + * include/std/functional (make_default_searcher) + (make_boyer_moore_searcher, make_boyer_moore_horspool_searcher): + Remove generator functions. + * include/std/tuple (tuple): Add deduction guides. + * include/std/valarray (valarray): Likewise. + * testsuite/20_util/function_objects/searchers.cc: Adjust to use + class template argument deduction instead of generator functions. + * testsuite/20_util/function/cons/deduction.cc: New test. + * testsuite/20_util/optional/cons/deduction_guide.cc: Rename to ... + * testsuite/20_util/optional/cons/deduction.cc: ... here. + * testsuite/20_util/pair/cons/deduction.cc: New test. + * testsuite/20_util/shared_ptr/cons/deduction.cc: New test. + * testsuite/20_util/tuple/cons/deduction.cc: New test. + * testsuite/20_util/tuple/element_access/get_neg.cc: Adjust dg-error. + * testsuite/20_util/unique_ptr/cons/deduction_neg.cc: New test. + * testsuite/20_util/weak_ptr/cons/deduction.cc: New test. + * testsuite/23_containers/array/cons/deduction.cc: New test. + * testsuite/23_containers/array/cons/deduction_neg.cc: New test. + * testsuite/23_containers/array/tuple_interface/get_debug_neg.cc: + Adjust dg-error. + * testsuite/23_containers/array/tuple_interface/get_neg.cc: Likewise. + * testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc: + Likewise. + * testsuite/26_numerics/valarray/deduction.cc: New test. + * testsuite/30_threads/lock_guard/cons/deduction.cc: New test. + * testsuite/30_threads/scoped_lock/cons/deduction.cc: New test. + * testsuite/30_threads/unique_lock/cons/deduction.cc: New test. + 2017-03-20 François Dumont * include/bits/stl_deque.h (deque): Access allocator value_type only if diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index 851f9cfa60c..fe933ff2afe 100644 --- a/libstdc++-v3/include/bits/shared_ptr.h +++ b/libstdc++-v3/include/bits/shared_ptr.h @@ -355,6 +355,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION friend class weak_ptr<_Tp>; }; +#if __cpp_deduction_guides >= 201606 + template + shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>; + template + shared_ptr(unique_ptr<_Tp, _Del>) -> shared_ptr<_Tp>; +#endif + // 20.7.2.2.7 shared_ptr comparisons template inline bool @@ -577,6 +584,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return shared_ptr<_Tp>(*this, std::nothrow); } }; +#if __cpp_deduction_guides >= 201606 + template + weak_ptr(shared_ptr<_Tp>) -> weak_ptr<_Tp>; +#endif + // 20.7.2.3.6 weak_ptr specialized algorithms. template inline void diff --git a/libstdc++-v3/include/bits/std_function.h b/libstdc++-v3/include/bits/std_function.h index 7d77e213b50..b393a944818 100644 --- a/libstdc++-v3/include/bits/std_function.h +++ b/libstdc++-v3/include/bits/std_function.h @@ -629,6 +629,43 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Invoker_type _M_invoker; }; +#if __cpp_deduction_guides >= 201606 + template + struct __function_guide_helper + { }; + + template + struct __function_guide_helper< + _Res (_Tp::*) (_Args...) noexcept(_Nx) + > + { using type = _Res(_Args...); }; + + template + struct __function_guide_helper< + _Res (_Tp::*) (_Args...) & noexcept(_Nx) + > + { using type = _Res(_Args...); }; + + template + struct __function_guide_helper< + _Res (_Tp::*) (_Args...) const noexcept(_Nx) + > + { using type = _Res(_Args...); }; + + template + struct __function_guide_helper< + _Res (_Tp::*) (_Args...) const & noexcept(_Nx) + > + { using type = _Res(_Args...); }; + + template + function(_Res(*)(_ArgTypes...)) -> function<_Res(_ArgTypes...)>; + + template::type> + function(_Functor) -> function<_Signature>; +#endif + // Out-of-line member definitions. template function<_Res(_ArgTypes...)>:: diff --git a/libstdc++-v3/include/bits/stl_pair.h b/libstdc++-v3/include/bits/stl_pair.h index e5e9f1c8c43..66f52b3358e 100644 --- a/libstdc++-v3/include/bits/stl_pair.h +++ b/libstdc++-v3/include/bits/stl_pair.h @@ -425,6 +425,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif }; +#if __cpp_deduction_guides >= 201606 + template pair(_T1, _T2) -> pair<_T1, _T2>; +#endif + /// Two pairs of the same type are equal iff their members are equal. template inline _GLIBCXX_CONSTEXPR bool diff --git a/libstdc++-v3/include/debug/array b/libstdc++-v3/include/debug/array index 3ff786a1247..9c279221040 100644 --- a/libstdc++-v3/include/debug/array +++ b/libstdc++-v3/include/debug/array @@ -225,6 +225,13 @@ namespace __debug { return _AT_Type::_S_ptr(_M_elems); } }; +#if __cpp_deduction_guides >= 201606 + template + array(_Tp, _Up...) + -> array && ...), _Tp>, + 1 + sizeof...(_Up)>; +#endif + // Array comparisons. template inline bool diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array index 261f2af4ced..1c7d6dc4ab1 100644 --- a/libstdc++-v3/include/std/array +++ b/libstdc++-v3/include/std/array @@ -239,6 +239,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { return _AT_Type::_S_ptr(_M_elems); } }; +#if __cpp_deduction_guides >= 201606 + template + array(_Tp, _Up...) + -> array && ...), _Tp>, + 1 + sizeof...(_Up)>; +#endif + // Array comparisons. template inline bool diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index ae5bc0a3bf9..3db10cade1c 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -1175,36 +1175,6 @@ _GLIBCXX_MEM_FN_TRAITS(&&, false_type, true_type) _RAIter _M_pat_end; }; - /// Generator function for default_searcher - template> - inline default_searcher<_ForwardIterator, _BinaryPredicate> - make_default_searcher(_ForwardIterator __pat_first, - _ForwardIterator __pat_last, - _BinaryPredicate __pred = _BinaryPredicate()) - { return { __pat_first, __pat_last, __pred }; } - - /// Generator function for boyer_moore_searcher - template::value_type>, - typename _BinaryPredicate = equal_to<>> - inline boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate> - make_boyer_moore_searcher(_RAIter __pat_first, _RAIter __pat_last, - _Hash __hf = _Hash(), - _BinaryPredicate __pred = _BinaryPredicate()) - { return { __pat_first, __pat_last, std::move(__hf), std::move(__pred) }; } - - /// Generator function for boyer_moore_horspool_searcher - template::value_type>, - typename _BinaryPredicate = equal_to<>> - inline boyer_moore_horspool_searcher<_RAIter, _Hash, _BinaryPredicate> - make_boyer_moore_horspool_searcher(_RAIter __pat_first, _RAIter __pat_last, - _Hash __hf = _Hash(), - _BinaryPredicate __pred - = _BinaryPredicate()) - { return { __pat_first, __pat_last, std::move(__hf), std::move(__pred) }; } - template boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>:: boyer_moore_searcher(_RAIter __pat, _RAIter __pat_end, diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index f53daf1b182..ae495d9dc51 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -872,6 +872,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { _Inherited::_M_swap(__in); } }; +#if __cpp_deduction_guides >= 201606 + template + tuple(_UTypes...) -> tuple<_UTypes...>; + template + tuple(pair<_T1, _T2>) -> tuple<_T1, _T2>; + template + tuple(allocator_arg_t, _Alloc, _UTypes...) -> tuple<_UTypes...>; + template + tuple(allocator_arg_t, _Alloc, pair<_T1, _T2>) -> tuple<_T1, _T2>; + template + tuple(allocator_arg_t, _Alloc, tuple<_UTypes...>) -> tuple<_UTypes...>; +#endif + // Explicit specialization, zero-element tuple. template<> class tuple<> diff --git a/libstdc++-v3/include/std/valarray b/libstdc++-v3/include/std/valarray index ad506503c93..2dc6e42ca05 100644 --- a/libstdc++-v3/include/std/valarray +++ b/libstdc++-v3/include/std/valarray @@ -563,6 +563,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION friend class _Array<_Tp>; }; +#if __cpp_deduction_guides >= 201606 + template + valarray(const _Tp(&)[_Nm], size_t) -> valarray<_Tp>; +#endif + template inline const _Tp& valarray<_Tp>::operator[](size_t __i) const diff --git a/libstdc++-v3/testsuite/20_util/function/cons/deduction.cc b/libstdc++-v3/testsuite/20_util/function/cons/deduction.cc new file mode 100644 index 00000000000..a4346e0accd --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/cons/deduction.cc @@ -0,0 +1,86 @@ +// 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 +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++1z } } + +#include + +template struct require_same; +template struct require_same { using type = void; }; + +template + typename require_same::type + check_type(U&) { } + +void f0v(); +void f0vn() noexcept; +int f0i(); +int f0in() noexcept; +long f1l(int&); +long f1ln(double*) noexcept; + +void +test01() +{ + std::function func1 = f0v; + check_type>(func1); + + std::function func2 = f0vn; + check_type>(func2); + + std::function func3 = f0i; + check_type>(func3); + + std::function func4 = f0in; + check_type>(func4); + + std::function func5 = f1l; + check_type>(func5); + + std::function func6 = f1ln; + check_type>(func6); + + std::function func5a = func5; + check_type>(func5a); + + std::function func6a = func6; + check_type>(func6a); +} + +struct X { + int operator()(const short&, void*); +}; + +struct Y { + void operator()(int) const & noexcept; +}; + +void +test02() +{ + X x; + std::function func1 = x; + check_type>(func1); + + Y y; + std::function func2 = y; + check_type>(func2); + + std::function func3 = [&x](float) -> X& { return x; }; + check_type>(func3); +} diff --git a/libstdc++-v3/testsuite/20_util/function_objects/searchers.cc b/libstdc++-v3/testsuite/20_util/function_objects/searchers.cc index 0506ea49069..9cc1455c85c 100644 --- a/libstdc++-v3/testsuite/20_util/function_objects/searchers.cc +++ b/libstdc++-v3/testsuite/20_util/function_objects/searchers.cc @@ -31,9 +31,9 @@ # error "Feature-test macro for searchers has wrong value" #endif -using std::make_default_searcher; -using std::make_boyer_moore_searcher; -using std::make_boyer_moore_horspool_searcher; +using std::default_searcher; +using std::boyer_moore_searcher; +using std::boyer_moore_horspool_searcher; void test01() @@ -50,9 +50,9 @@ test01() for (auto n : needles) { auto ne = n + std::strlen(n); - auto d = make_default_searcher(n, ne); - auto bm = make_boyer_moore_searcher(n, ne); - auto bmh = make_boyer_moore_horspool_searcher(n, ne); + default_searcher d(n, ne); + boyer_moore_searcher bm(n, ne); + boyer_moore_horspool_searcher bmh(n, ne); for (auto h : haystacks) { auto he = h + std::strlen(h); @@ -83,9 +83,9 @@ test02() for (auto n : needles) { auto ne = n + std::wcslen(n); - auto d = make_default_searcher(n, ne); - auto bm = make_boyer_moore_searcher(n, ne); - auto bmh = make_boyer_moore_horspool_searcher(n, ne); + default_searcher d(n, ne); + boyer_moore_searcher bm(n, ne); + boyer_moore_horspool_searcher bmh(n, ne); for (auto h : haystacks) { auto he = h + std::wcslen(h); @@ -122,9 +122,9 @@ test03() const char* ne = needle + std::strlen(needle); const char* he = haystack + std::strlen(haystack); - auto d = make_default_searcher(needle, ne, eq); - auto bm = make_boyer_moore_searcher(needle, ne, eq, eq); - auto bmh = make_boyer_moore_horspool_searcher(needle, ne, eq, eq); + default_searcher d(needle, ne, eq); + boyer_moore_searcher bm(needle, ne, eq, eq); + boyer_moore_horspool_searcher bmh(needle, ne, eq, eq); auto res = std::search(haystack, he, needle, ne, eq); auto d_res = d(haystack, he); diff --git a/libstdc++-v3/testsuite/20_util/optional/cons/deduction_guide.cc b/libstdc++-v3/testsuite/20_util/optional/cons/deduction.cc similarity index 61% rename from libstdc++-v3/testsuite/20_util/optional/cons/deduction_guide.cc rename to libstdc++-v3/testsuite/20_util/optional/cons/deduction.cc index 59698dcf263..e15db0bc1ec 100644 --- a/libstdc++-v3/testsuite/20_util/optional/cons/deduction_guide.cc +++ b/libstdc++-v3/testsuite/20_util/optional/cons/deduction.cc @@ -1,6 +1,3 @@ -// { dg-options "-std=gnu++17" } -// { dg-do compile } - // Copyright (C) 2017 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -18,6 +15,9 @@ // with this library; see the file COPYING3. If not see // . +// { dg-options "-std=gnu++17" } +// { dg-do compile } + #include #include @@ -30,15 +30,20 @@ struct MoveOnly int main() { - std::optional x = 5; - static_assert(std::is_same_v>); - int y = 42; - std::optional x2 = y; - static_assert(std::is_same_v>); - const int z = 666; - std::optional x3 = z; - static_assert(std::is_same_v>); - std::optional mo = MoveOnly(); - static_assert(std::is_same_v>); - mo = MoveOnly(); + std::optional x = 5; + static_assert(std::is_same_v>); + int y = 42; + std::optional x2 = y; + static_assert(std::is_same_v>); + const int z = 666; + std::optional x3 = z; + static_assert(std::is_same_v>); + std::optional mo = MoveOnly(); + static_assert(std::is_same_v>); + mo = MoveOnly(); + + std::optional copy = x; + static_assert(std::is_same_v>); + std::optional move = std::move(mo); + static_assert(std::is_same_v>); } diff --git a/libstdc++-v3/testsuite/20_util/pair/cons/deduction.cc b/libstdc++-v3/testsuite/20_util/pair/cons/deduction.cc new file mode 100644 index 00000000000..c8e6fd60591 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/cons/deduction.cc @@ -0,0 +1,60 @@ +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++1z } } + +// 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 +// . + +#include + +template struct require_same; +template struct require_same { using type = void; }; + +template + typename require_same::type + check_type(U&) { } + +struct MoveOnly +{ + MoveOnly() = default; + MoveOnly(MoveOnly&&) {} + MoveOnly& operator=(MoveOnly&&) {} +}; + +void +test01() +{ + std::pair x{5, 6u}; + check_type>(x); + int y = 42; + std::pair x2{y, 48u}; + check_type>(x2); + const int z = 666; + std::pair x3{z, y}; + check_type>(x3); + std::pair x4{1, x}; + check_type>>(x4); + std::pair mo{MoveOnly(), 2l}; + check_type>(mo); + mo = {MoveOnly(), 3l}; + + std::pair copy = x; + check_type(copy); + std::pair copy2{x}; + check_type(copy2); + std::pair move = std::move(mo); + check_type(move); +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/deduction.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/deduction.cc new file mode 100644 index 00000000000..ecd0780fbc2 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/deduction.cc @@ -0,0 +1,45 @@ +// 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 +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++1z } } + +#include + +template struct require_same; +template struct require_same { using type = void; }; + +template + typename require_same::type + check_type(U&) { } + +void +test01() +{ + std::shared_ptr s; + std::shared_ptr s2 = s; + check_type>(s2); + + std::weak_ptr w; + std::shared_ptr s3(w); + check_type>(s3); + + struct D { void operator()(double*) { } }; + std::unique_ptr u; + std::shared_ptr s4 = std::move(u); + check_type>(s4); +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/deduction.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/deduction.cc new file mode 100644 index 00000000000..47e2488348a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/deduction.cc @@ -0,0 +1,166 @@ +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++1z } } + +// 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 +// . + +#include + +template struct require_same; +template struct require_same { using type = void; }; + +template + typename require_same::type + check_type(U&) { } + +struct MoveOnly +{ + MoveOnly() = default; + MoveOnly(MoveOnly&&) {} + MoveOnly& operator=(MoveOnly&&) {} +}; + +void +test00() +{ + std::tuple x; + check_type>(x); + + std::tuple copy = x; + check_type(copy); + std::tuple move = std::move(x); + check_type(move); +} + +void +test01() +{ + std::tuple x = 5; + check_type>(x); + int y = 42; + std::tuple x2 = y; + check_type>(x2); + const int z = 666; + std::tuple x3 = z; + check_type>(x3); + std::tuple mo = MoveOnly(); + check_type>(mo); + mo = MoveOnly(); + + std::tuple copy = x; + check_type(copy); + std::tuple move = std::move(mo); + check_type(move); +} + +void +test02() +{ + std::tuple x{5, 6u}; + check_type>(x); + int y = 42; + std::tuple x2{y, 48u}; + check_type>(x2); + const int z = 666; + std::tuple x3{z, y}; + check_type>(x3); + std::tuple x4{1, x}; + check_type>(x4); + std::tuple mo{MoveOnly(), 2l}; + check_type>(mo); + mo = {MoveOnly(), 3l}; + + std::tuple copy = x; + check_type(copy); + std::tuple copy2{x}; + check_type(copy2); + std::tuple move = std::move(mo); + check_type(move); +} + +void +test03() +{ + std::tuple x{5, 6u, '7'}; + check_type>(x); + int y = 42; + std::tuple x2{y, 48u, 54l}; + check_type>(x2); + const int z = 666; + std::tuple x3{z, y, x}; + check_type>(x3); + std::tuple x4{1, x, x2}; + check_type>(x4); + std::tuple mo{MoveOnly(), 2l}; + check_type>(mo); + mo = {MoveOnly(), 3l}; + + std::tuple copy = x; + check_type(copy); + std::tuple copy2{x}; + check_type(copy2); + std::tuple move = std::move(mo); + check_type(move); +} + +void +test04() +{ + std::pair p; + std::tuple x = p; + check_type>(x); + int y = 42; + std::tuple x2{p}; + check_type>(x2); + const int z = 666; + std::pair p2; + std::tuple x3{p2}; + check_type>(x3); + std::pair p3{p.first, p.second}; + std::tuple x4{p3}; + check_type>(x4); + std::tuple mo = std::pair(); + check_type>(mo); + + std::tuple copy = x4; + check_type(copy); + std::tuple copy2{x4}; + check_type(copy2); + std::tuple move = std::move(mo); + check_type(move); +} + +void +test05() +{ + std::allocator a; + std::tuple x{std::allocator_arg, a, 1}; + check_type>(x); + std::tuple x2{std::allocator_arg, a, 1, '2'}; + check_type>(x2); + + std::pair p{}; + std::tuple x3{std::allocator_arg, a, p}; + check_type>(x3); + std::tuple x4{std::allocator_arg, a, std::move(p)}; + check_type>(x4); + + std::tuple x5{std::allocator_arg, a, x}; + check_type(x5); + std::tuple x6{std::allocator_arg, a, std::move(x)}; + check_type(x6); +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/element_access/get_neg.cc b/libstdc++-v3/testsuite/20_util/tuple/element_access/get_neg.cc index 0dc62a226b8..03835f40188 100644 --- a/libstdc++-v3/testsuite/20_util/tuple/element_access/get_neg.cc +++ b/libstdc++-v3/testsuite/20_util/tuple/element_access/get_neg.cc @@ -17,7 +17,7 @@ // { dg-options "-fno-show-column" } // { dg-do compile { target c++14 } } -// { dg-error "in range" "" { target *-*-* } 1284 } +// { dg-error "in range" "" { target *-*-* } 1297 } #include diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/deduction_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/deduction_neg.cc new file mode 100644 index 00000000000..23aca62caad --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/deduction_neg.cc @@ -0,0 +1,36 @@ +// 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 +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++1z } } + +#include + +void +test01() +{ + std::unique_ptr s; + std::unique_ptr s2 = std::move(s); // OK + + std::unique_ptr bad{new int}; // { dg-error "class template argument deduction failed" } + + struct D { void operator()(double*) { } }; + std::unique_ptr bad2{new double, D()}; // { dg-error "class template argument deduction failed" } +} + +// { dg-error "no matching function" "" { target *-*-* } 29 } +// { dg-error "no matching function" "" { target *-*-* } 32 } diff --git a/libstdc++-v3/testsuite/20_util/weak_ptr/cons/deduction.cc b/libstdc++-v3/testsuite/20_util/weak_ptr/cons/deduction.cc new file mode 100644 index 00000000000..ea384172aca --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/weak_ptr/cons/deduction.cc @@ -0,0 +1,39 @@ +// 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 +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++1z } } + +#include + +template struct require_same; +template struct require_same { using type = void; }; + +template + typename require_same::type + check_type(U&) { } + +void +test01() +{ + std::shared_ptr s; + std::weak_ptr w(s); + check_type>(w); + + std::weak_ptr w2(w); + check_type>(w2); +} diff --git a/libstdc++-v3/testsuite/23_containers/array/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/array/cons/deduction.cc new file mode 100644 index 00000000000..5ce2909d832 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/array/cons/deduction.cc @@ -0,0 +1,46 @@ +// 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 +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++1z } } + +#include + +template struct require_same; +template struct require_same { using type = void; }; + +template + typename require_same::type + check_type(U&) { } + +void +test01() +{ + std::array a1{ 1, 2, 3 }; + check_type>(a1); + int y = 2; + const int z = 3; + std::array a2{ 1, y, z }; + check_type>(a2); + std::array a3{ 'a', 'b', 'c', 'd', 'e' }; + check_type>(a3); + + std::array copy = a1; + check_type(copy); + std::array move = std::move(a1); + check_type(move); +} diff --git a/libstdc++-v3/testsuite/23_containers/array/cons/deduction_neg.cc b/libstdc++-v3/testsuite/23_containers/array/cons/deduction_neg.cc new file mode 100644 index 00000000000..ec11b05a54c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/array/cons/deduction_neg.cc @@ -0,0 +1,31 @@ +// 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 +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++1z } } + +#include + +void +test01() +{ + std::array a1{}; // { dg-error "class template argument deduction failed" } + std::array a2{1, 2u, 3}; // { dg-error "class template argument deduction failed" } +} +// { dg-error "no matching function for call" "" { target *-*-* } 26 } +// { dg-error "no matching function for call" "" { target *-*-* } 27 } +// { dg-error "no type named .*enable_if" "" { target *-*-* } 0 } diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_debug_neg.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_debug_neg.cc index 03d284b0a4e..81d8b931753 100644 --- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_debug_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_debug_neg.cc @@ -27,6 +27,6 @@ int n1 = std::get<1>(a); int n2 = std::get<1>(std::move(a)); int n3 = std::get<1>(ca); -// { dg-error "static assertion failed" "" { target *-*-* } 281 } -// { dg-error "static assertion failed" "" { target *-*-* } 290 } -// { dg-error "static assertion failed" "" { target *-*-* } 298 } +// { dg-error "static assertion failed" "" { target *-*-* } 288 } +// { dg-error "static assertion failed" "" { target *-*-* } 297 } +// { dg-error "static assertion failed" "" { target *-*-* } 305 } diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc index 0b9ca95f57a..8983ad7c7b2 100644 --- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc @@ -27,6 +27,6 @@ int n1 = std::get<1>(a); int n2 = std::get<1>(std::move(a)); int n3 = std::get<1>(ca); -// { dg-error "static assertion failed" "" { target *-*-* } 302 } -// { dg-error "static assertion failed" "" { target *-*-* } 311 } -// { dg-error "static assertion failed" "" { target *-*-* } 319 } +// { dg-error "static assertion failed" "" { target *-*-* } 309 } +// { dg-error "static assertion failed" "" { target *-*-* } 318 } +// { dg-error "static assertion failed" "" { target *-*-* } 326 } diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc index c6a8d00218f..493449a235b 100644 --- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc @@ -22,4 +22,4 @@ typedef std::tuple_element<1, std::array>::type type; -// { dg-error "static assertion failed" "" { target *-*-* } 350 } +// { dg-error "static assertion failed" "" { target *-*-* } 357 } diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/deduction.cc b/libstdc++-v3/testsuite/26_numerics/valarray/deduction.cc new file mode 100644 index 00000000000..72d4bc09126 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/deduction.cc @@ -0,0 +1,42 @@ +// 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 +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++1z } } + +#include + +template struct require_same; +template struct require_same { using type = void; }; + +template + typename require_same::type + check_type(U&) { } + +void +test01() +{ + int arr[4] = { 1, 2, 3, 4 }; + std::valarray v(arr, 4); + check_type>(v); + + std::valarray v2 = v; + check_type>(v2); + + std::valarray v3 = std::move(v); + check_type>(v3); +} diff --git a/libstdc++-v3/testsuite/30_threads/lock_guard/cons/deduction.cc b/libstdc++-v3/testsuite/30_threads/lock_guard/cons/deduction.cc new file mode 100644 index 00000000000..b72c1a12a40 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/lock_guard/cons/deduction.cc @@ -0,0 +1,44 @@ +// 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 +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++1z } } + +#include + +template struct require_same; +template struct require_same { using type = void; }; + +template + typename require_same::type + check_type(U&) { } + +void +test01() +{ + std::mutex m; + std::lock_guard l(m); + check_type>(l); + + struct Mutex { + void lock() { } + void unlock() { } + } m2; + + std::lock_guard l2(m2); + check_type>(l2); +} diff --git a/libstdc++-v3/testsuite/30_threads/scoped_lock/cons/deduction.cc b/libstdc++-v3/testsuite/30_threads/scoped_lock/cons/deduction.cc new file mode 100644 index 00000000000..399de7a5ae6 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/scoped_lock/cons/deduction.cc @@ -0,0 +1,53 @@ +// 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 +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++1z } } + +#include + +template struct require_same; +template struct require_same { using type = void; }; + +template + typename require_same::type + check_type(U&) { } + +void +test01() +{ + std::scoped_lock l0; + check_type>(l0); + + struct BasicLockable { + void lock() { } + void unlock() { } + } m1; + + std::scoped_lock l1(m1); + check_type>(l1); + + struct Lockable { + void lock() { } + void unlock() { } + bool try_lock() { return true; } + } m2; + + std::mutex m3; + std::scoped_lock l2(m2, m3); + check_type>(l2); +} diff --git a/libstdc++-v3/testsuite/30_threads/unique_lock/cons/deduction.cc b/libstdc++-v3/testsuite/30_threads/unique_lock/cons/deduction.cc new file mode 100644 index 00000000000..4f36bab9d6a --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/unique_lock/cons/deduction.cc @@ -0,0 +1,44 @@ +// 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 +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++1z } } + +#include + +template struct require_same; +template struct require_same { using type = void; }; + +template + typename require_same::type + check_type(U&) { } + +void +test01() +{ + std::mutex m; + std::unique_lock l(m); + check_type>(l); + + struct Mutex { + void lock() { } + void unlock() { } + } m2; + + std::unique_lock l2(m2); + check_type>(l2); +} -- 2.30.2