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
This commit is contained in:
parent
918b6c9ec2
commit
af181c91a9
27 changed files with 852 additions and 64 deletions
|
@ -1,3 +1,39 @@
|
|||
2017-03-22 Jonathan Wakely <jwakely@redhat.com>
|
||||
|
||||
* 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 <fdumont@gcc.gnu.org>
|
||||
|
||||
* include/bits/stl_deque.h (deque): Access allocator value_type only if
|
||||
|
|
|
@ -355,6 +355,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
friend class weak_ptr<_Tp>;
|
||||
};
|
||||
|
||||
#if __cpp_deduction_guides >= 201606
|
||||
template<typename _Tp>
|
||||
shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>;
|
||||
template<typename _Tp, typename _Del>
|
||||
shared_ptr(unique_ptr<_Tp, _Del>) -> shared_ptr<_Tp>;
|
||||
#endif
|
||||
|
||||
// 20.7.2.2.7 shared_ptr comparisons
|
||||
template<typename _Tp, typename _Up>
|
||||
inline bool
|
||||
|
@ -577,6 +584,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
{ return shared_ptr<_Tp>(*this, std::nothrow); }
|
||||
};
|
||||
|
||||
#if __cpp_deduction_guides >= 201606
|
||||
template<typename _Tp>
|
||||
weak_ptr(shared_ptr<_Tp>) -> weak_ptr<_Tp>;
|
||||
#endif
|
||||
|
||||
// 20.7.2.3.6 weak_ptr specialized algorithms.
|
||||
template<typename _Tp>
|
||||
inline void
|
||||
|
|
|
@ -629,6 +629,43 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
_Invoker_type _M_invoker;
|
||||
};
|
||||
|
||||
#if __cpp_deduction_guides >= 201606
|
||||
template<typename>
|
||||
struct __function_guide_helper
|
||||
{ };
|
||||
|
||||
template<typename _Res, typename _Tp, bool _Nx, typename... _Args>
|
||||
struct __function_guide_helper<
|
||||
_Res (_Tp::*) (_Args...) noexcept(_Nx)
|
||||
>
|
||||
{ using type = _Res(_Args...); };
|
||||
|
||||
template<typename _Res, typename _Tp, bool _Nx, typename... _Args>
|
||||
struct __function_guide_helper<
|
||||
_Res (_Tp::*) (_Args...) & noexcept(_Nx)
|
||||
>
|
||||
{ using type = _Res(_Args...); };
|
||||
|
||||
template<typename _Res, typename _Tp, bool _Nx, typename... _Args>
|
||||
struct __function_guide_helper<
|
||||
_Res (_Tp::*) (_Args...) const noexcept(_Nx)
|
||||
>
|
||||
{ using type = _Res(_Args...); };
|
||||
|
||||
template<typename _Res, typename _Tp, bool _Nx, typename... _Args>
|
||||
struct __function_guide_helper<
|
||||
_Res (_Tp::*) (_Args...) const & noexcept(_Nx)
|
||||
>
|
||||
{ using type = _Res(_Args...); };
|
||||
|
||||
template<typename _Res, typename... _ArgTypes>
|
||||
function(_Res(*)(_ArgTypes...)) -> function<_Res(_ArgTypes...)>;
|
||||
|
||||
template<typename _Functor, typename _Signature = typename
|
||||
__function_guide_helper<decltype(&_Functor::operator())>::type>
|
||||
function(_Functor) -> function<_Signature>;
|
||||
#endif
|
||||
|
||||
// Out-of-line member definitions.
|
||||
template<typename _Res, typename... _ArgTypes>
|
||||
function<_Res(_ArgTypes...)>::
|
||||
|
|
|
@ -425,6 +425,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
#endif
|
||||
};
|
||||
|
||||
#if __cpp_deduction_guides >= 201606
|
||||
template<typename _T1, typename _T2> pair(_T1, _T2) -> pair<_T1, _T2>;
|
||||
#endif
|
||||
|
||||
/// Two pairs of the same type are equal iff their members are equal.
|
||||
template<typename _T1, typename _T2>
|
||||
inline _GLIBCXX_CONSTEXPR bool
|
||||
|
|
|
@ -225,6 +225,13 @@ namespace __debug
|
|||
{ return _AT_Type::_S_ptr(_M_elems); }
|
||||
};
|
||||
|
||||
#if __cpp_deduction_guides >= 201606
|
||||
template<typename _Tp, typename... _Up>
|
||||
array(_Tp, _Up...)
|
||||
-> array<std::enable_if_t<(std::is_same_v<_Tp, _Up> && ...), _Tp>,
|
||||
1 + sizeof...(_Up)>;
|
||||
#endif
|
||||
|
||||
// Array comparisons.
|
||||
template<typename _Tp, std::size_t _Nm>
|
||||
inline bool
|
||||
|
|
|
@ -239,6 +239,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
|
|||
{ return _AT_Type::_S_ptr(_M_elems); }
|
||||
};
|
||||
|
||||
#if __cpp_deduction_guides >= 201606
|
||||
template<typename _Tp, typename... _Up>
|
||||
array(_Tp, _Up...)
|
||||
-> array<enable_if_t<(is_same_v<_Tp, _Up> && ...), _Tp>,
|
||||
1 + sizeof...(_Up)>;
|
||||
#endif
|
||||
|
||||
// Array comparisons.
|
||||
template<typename _Tp, std::size_t _Nm>
|
||||
inline bool
|
||||
|
|
|
@ -1175,36 +1175,6 @@ _GLIBCXX_MEM_FN_TRAITS(&&, false_type, true_type)
|
|||
_RAIter _M_pat_end;
|
||||
};
|
||||
|
||||
/// Generator function for default_searcher
|
||||
template<typename _ForwardIterator,
|
||||
typename _BinaryPredicate = std::equal_to<>>
|
||||
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<typename _RAIter, typename _Hash
|
||||
= std::hash<typename std::iterator_traits<_RAIter>::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<typename _RAIter, typename _Hash
|
||||
= std::hash<typename std::iterator_traits<_RAIter>::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<typename _RAIter, typename _Hash, typename _BinaryPredicate>
|
||||
boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
|
||||
boyer_moore_searcher(_RAIter __pat, _RAIter __pat_end,
|
||||
|
|
|
@ -872,6 +872,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
{ _Inherited::_M_swap(__in); }
|
||||
};
|
||||
|
||||
#if __cpp_deduction_guides >= 201606
|
||||
template<typename... _UTypes>
|
||||
tuple(_UTypes...) -> tuple<_UTypes...>;
|
||||
template<typename _T1, typename _T2>
|
||||
tuple(pair<_T1, _T2>) -> tuple<_T1, _T2>;
|
||||
template<typename _Alloc, typename... _UTypes>
|
||||
tuple(allocator_arg_t, _Alloc, _UTypes...) -> tuple<_UTypes...>;
|
||||
template<typename _Alloc, typename _T1, typename _T2>
|
||||
tuple(allocator_arg_t, _Alloc, pair<_T1, _T2>) -> tuple<_T1, _T2>;
|
||||
template<typename _Alloc, typename... _UTypes>
|
||||
tuple(allocator_arg_t, _Alloc, tuple<_UTypes...>) -> tuple<_UTypes...>;
|
||||
#endif
|
||||
|
||||
// Explicit specialization, zero-element tuple.
|
||||
template<>
|
||||
class tuple<>
|
||||
|
|
|
@ -563,6 +563,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
friend class _Array<_Tp>;
|
||||
};
|
||||
|
||||
#if __cpp_deduction_guides >= 201606
|
||||
template<typename _Tp, size_t _Nm>
|
||||
valarray(const _Tp(&)[_Nm], size_t) -> valarray<_Tp>;
|
||||
#endif
|
||||
|
||||
template<typename _Tp>
|
||||
inline const _Tp&
|
||||
valarray<_Tp>::operator[](size_t __i) const
|
||||
|
|
86
libstdc++-v3/testsuite/20_util/function/cons/deduction.cc
Normal file
86
libstdc++-v3/testsuite/20_util/function/cons/deduction.cc
Normal file
|
@ -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
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
// { dg-do compile { target c++1z } }
|
||||
|
||||
#include <functional>
|
||||
|
||||
template<typename T, typename U> struct require_same;
|
||||
template<typename T> struct require_same<T, T> { using type = void; };
|
||||
|
||||
template<typename T, typename U>
|
||||
typename require_same<T, U>::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<std::function<void()>>(func1);
|
||||
|
||||
std::function func2 = f0vn;
|
||||
check_type<std::function<void()>>(func2);
|
||||
|
||||
std::function func3 = f0i;
|
||||
check_type<std::function<int()>>(func3);
|
||||
|
||||
std::function func4 = f0in;
|
||||
check_type<std::function<int()>>(func4);
|
||||
|
||||
std::function func5 = f1l;
|
||||
check_type<std::function<long(int&)>>(func5);
|
||||
|
||||
std::function func6 = f1ln;
|
||||
check_type<std::function<long(double*)>>(func6);
|
||||
|
||||
std::function func5a = func5;
|
||||
check_type<std::function<long(int&)>>(func5a);
|
||||
|
||||
std::function func6a = func6;
|
||||
check_type<std::function<long(double*)>>(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<std::function<int(const short&, void*)>>(func1);
|
||||
|
||||
Y y;
|
||||
std::function func2 = y;
|
||||
check_type<std::function<void(int)>>(func2);
|
||||
|
||||
std::function func3 = [&x](float) -> X& { return x; };
|
||||
check_type<std::function<X&(float)>>(func3);
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
// { dg-do compile }
|
||||
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
|
||||
|
@ -30,15 +30,20 @@ struct MoveOnly
|
|||
|
||||
int main()
|
||||
{
|
||||
std::optional x = 5;
|
||||
static_assert(std::is_same_v<decltype(x), std::optional<int>>);
|
||||
int y = 42;
|
||||
std::optional x2 = y;
|
||||
static_assert(std::is_same_v<decltype(x2), std::optional<int>>);
|
||||
const int z = 666;
|
||||
std::optional x3 = z;
|
||||
static_assert(std::is_same_v<decltype(x3), std::optional<int>>);
|
||||
std::optional mo = MoveOnly();
|
||||
static_assert(std::is_same_v<decltype(mo), std::optional<MoveOnly>>);
|
||||
mo = MoveOnly();
|
||||
std::optional x = 5;
|
||||
static_assert(std::is_same_v<decltype(x), std::optional<int>>);
|
||||
int y = 42;
|
||||
std::optional x2 = y;
|
||||
static_assert(std::is_same_v<decltype(x2), std::optional<int>>);
|
||||
const int z = 666;
|
||||
std::optional x3 = z;
|
||||
static_assert(std::is_same_v<decltype(x3), std::optional<int>>);
|
||||
std::optional mo = MoveOnly();
|
||||
static_assert(std::is_same_v<decltype(mo), std::optional<MoveOnly>>);
|
||||
mo = MoveOnly();
|
||||
|
||||
std::optional copy = x;
|
||||
static_assert(std::is_same_v<decltype(copy), std::optional<int>>);
|
||||
std::optional move = std::move(mo);
|
||||
static_assert(std::is_same_v<decltype(move), std::optional<MoveOnly>>);
|
||||
}
|
60
libstdc++-v3/testsuite/20_util/pair/cons/deduction.cc
Normal file
60
libstdc++-v3/testsuite/20_util/pair/cons/deduction.cc
Normal file
|
@ -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
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <utility>
|
||||
|
||||
template<typename T, typename U> struct require_same;
|
||||
template<typename T> struct require_same<T, T> { using type = void; };
|
||||
|
||||
template<typename T, typename U>
|
||||
typename require_same<T, U>::type
|
||||
check_type(U&) { }
|
||||
|
||||
struct MoveOnly
|
||||
{
|
||||
MoveOnly() = default;
|
||||
MoveOnly(MoveOnly&&) {}
|
||||
MoveOnly& operator=(MoveOnly&&) {}
|
||||
};
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
std::pair x{5, 6u};
|
||||
check_type<std::pair<int, unsigned>>(x);
|
||||
int y = 42;
|
||||
std::pair x2{y, 48u};
|
||||
check_type<std::pair<int, unsigned>>(x2);
|
||||
const int z = 666;
|
||||
std::pair x3{z, y};
|
||||
check_type<std::pair<int, int>>(x3);
|
||||
std::pair x4{1, x};
|
||||
check_type<std::pair<int, std::pair<int, unsigned>>>(x4);
|
||||
std::pair mo{MoveOnly(), 2l};
|
||||
check_type<std::pair<MoveOnly, long>>(mo);
|
||||
mo = {MoveOnly(), 3l};
|
||||
|
||||
std::pair copy = x;
|
||||
check_type<decltype(x)>(copy);
|
||||
std::pair copy2{x};
|
||||
check_type<decltype(x)>(copy2);
|
||||
std::pair move = std::move(mo);
|
||||
check_type<decltype(mo)>(move);
|
||||
}
|
45
libstdc++-v3/testsuite/20_util/shared_ptr/cons/deduction.cc
Normal file
45
libstdc++-v3/testsuite/20_util/shared_ptr/cons/deduction.cc
Normal file
|
@ -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
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
// { dg-do compile { target c++1z } }
|
||||
|
||||
#include <memory>
|
||||
|
||||
template<typename T, typename U> struct require_same;
|
||||
template<typename T> struct require_same<T, T> { using type = void; };
|
||||
|
||||
template<typename T, typename U>
|
||||
typename require_same<T, U>::type
|
||||
check_type(U&) { }
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
std::shared_ptr<long> s;
|
||||
std::shared_ptr s2 = s;
|
||||
check_type<std::shared_ptr<long>>(s2);
|
||||
|
||||
std::weak_ptr<long> w;
|
||||
std::shared_ptr s3(w);
|
||||
check_type<std::shared_ptr<long>>(s3);
|
||||
|
||||
struct D { void operator()(double*) { } };
|
||||
std::unique_ptr<double, D> u;
|
||||
std::shared_ptr s4 = std::move(u);
|
||||
check_type<std::shared_ptr<double>>(s4);
|
||||
}
|
166
libstdc++-v3/testsuite/20_util/tuple/cons/deduction.cc
Normal file
166
libstdc++-v3/testsuite/20_util/tuple/cons/deduction.cc
Normal file
|
@ -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
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <tuple>
|
||||
|
||||
template<typename T, typename U> struct require_same;
|
||||
template<typename T> struct require_same<T, T> { using type = void; };
|
||||
|
||||
template<typename T, typename U>
|
||||
typename require_same<T, U>::type
|
||||
check_type(U&) { }
|
||||
|
||||
struct MoveOnly
|
||||
{
|
||||
MoveOnly() = default;
|
||||
MoveOnly(MoveOnly&&) {}
|
||||
MoveOnly& operator=(MoveOnly&&) {}
|
||||
};
|
||||
|
||||
void
|
||||
test00()
|
||||
{
|
||||
std::tuple x;
|
||||
check_type<std::tuple<>>(x);
|
||||
|
||||
std::tuple copy = x;
|
||||
check_type<decltype(x)>(copy);
|
||||
std::tuple move = std::move(x);
|
||||
check_type<decltype(x)>(move);
|
||||
}
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
std::tuple x = 5;
|
||||
check_type<std::tuple<int>>(x);
|
||||
int y = 42;
|
||||
std::tuple x2 = y;
|
||||
check_type<std::tuple<int>>(x2);
|
||||
const int z = 666;
|
||||
std::tuple x3 = z;
|
||||
check_type<std::tuple<int>>(x3);
|
||||
std::tuple mo = MoveOnly();
|
||||
check_type<std::tuple<MoveOnly>>(mo);
|
||||
mo = MoveOnly();
|
||||
|
||||
std::tuple copy = x;
|
||||
check_type<decltype(x)>(copy);
|
||||
std::tuple move = std::move(mo);
|
||||
check_type<decltype(mo)>(move);
|
||||
}
|
||||
|
||||
void
|
||||
test02()
|
||||
{
|
||||
std::tuple x{5, 6u};
|
||||
check_type<std::tuple<int, unsigned>>(x);
|
||||
int y = 42;
|
||||
std::tuple x2{y, 48u};
|
||||
check_type<std::tuple<int, unsigned>>(x2);
|
||||
const int z = 666;
|
||||
std::tuple x3{z, y};
|
||||
check_type<std::tuple<int, int>>(x3);
|
||||
std::tuple x4{1, x};
|
||||
check_type<std::tuple<int, decltype(x)>>(x4);
|
||||
std::tuple mo{MoveOnly(), 2l};
|
||||
check_type<std::tuple<MoveOnly, long>>(mo);
|
||||
mo = {MoveOnly(), 3l};
|
||||
|
||||
std::tuple copy = x;
|
||||
check_type<decltype(x)>(copy);
|
||||
std::tuple copy2{x};
|
||||
check_type<decltype(x)>(copy2);
|
||||
std::tuple move = std::move(mo);
|
||||
check_type<decltype(mo)>(move);
|
||||
}
|
||||
|
||||
void
|
||||
test03()
|
||||
{
|
||||
std::tuple x{5, 6u, '7'};
|
||||
check_type<std::tuple<int, unsigned, char>>(x);
|
||||
int y = 42;
|
||||
std::tuple x2{y, 48u, 54l};
|
||||
check_type<std::tuple<int, unsigned, long>>(x2);
|
||||
const int z = 666;
|
||||
std::tuple x3{z, y, x};
|
||||
check_type<std::tuple<int, int, decltype(x)>>(x3);
|
||||
std::tuple x4{1, x, x2};
|
||||
check_type<std::tuple<int, decltype(x), decltype(x2)>>(x4);
|
||||
std::tuple mo{MoveOnly(), 2l};
|
||||
check_type<std::tuple<MoveOnly, long>>(mo);
|
||||
mo = {MoveOnly(), 3l};
|
||||
|
||||
std::tuple copy = x;
|
||||
check_type<decltype(x)>(copy);
|
||||
std::tuple copy2{x};
|
||||
check_type<decltype(x)>(copy2);
|
||||
std::tuple move = std::move(mo);
|
||||
check_type<decltype(mo)>(move);
|
||||
}
|
||||
|
||||
void
|
||||
test04()
|
||||
{
|
||||
std::pair<int, unsigned> p;
|
||||
std::tuple x = p;
|
||||
check_type<std::tuple<int, unsigned>>(x);
|
||||
int y = 42;
|
||||
std::tuple x2{p};
|
||||
check_type<std::tuple<int, unsigned>>(x2);
|
||||
const int z = 666;
|
||||
std::pair<const int, unsigned> p2;
|
||||
std::tuple x3{p2};
|
||||
check_type<std::tuple<const int, unsigned>>(x3);
|
||||
std::pair<int&, const unsigned&> p3{p.first, p.second};
|
||||
std::tuple x4{p3};
|
||||
check_type<std::tuple<int&, const unsigned&>>(x4);
|
||||
std::tuple mo = std::pair<MoveOnly, MoveOnly>();
|
||||
check_type<std::tuple<MoveOnly, MoveOnly>>(mo);
|
||||
|
||||
std::tuple copy = x4;
|
||||
check_type<decltype(x4)>(copy);
|
||||
std::tuple copy2{x4};
|
||||
check_type<decltype(x4)>(copy2);
|
||||
std::tuple move = std::move(mo);
|
||||
check_type<decltype(mo)>(move);
|
||||
}
|
||||
|
||||
void
|
||||
test05()
|
||||
{
|
||||
std::allocator<double> a;
|
||||
std::tuple x{std::allocator_arg, a, 1};
|
||||
check_type<std::tuple<int>>(x);
|
||||
std::tuple x2{std::allocator_arg, a, 1, '2'};
|
||||
check_type<std::tuple<int, char>>(x2);
|
||||
|
||||
std::pair<float, const short> p{};
|
||||
std::tuple x3{std::allocator_arg, a, p};
|
||||
check_type<std::tuple<float, const short>>(x3);
|
||||
std::tuple x4{std::allocator_arg, a, std::move(p)};
|
||||
check_type<std::tuple<float, const short>>(x4);
|
||||
|
||||
std::tuple x5{std::allocator_arg, a, x};
|
||||
check_type<decltype(x)>(x5);
|
||||
std::tuple x6{std::allocator_arg, a, std::move(x)};
|
||||
check_type<decltype(x)>(x6);
|
||||
}
|
|
@ -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 <tuple>
|
||||
|
||||
|
|
|
@ -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
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
// { dg-do compile { target c++1z } }
|
||||
|
||||
#include <memory>
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
std::unique_ptr<long> 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 }
|
39
libstdc++-v3/testsuite/20_util/weak_ptr/cons/deduction.cc
Normal file
39
libstdc++-v3/testsuite/20_util/weak_ptr/cons/deduction.cc
Normal file
|
@ -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
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
// { dg-do compile { target c++1z } }
|
||||
|
||||
#include <memory>
|
||||
|
||||
template<typename T, typename U> struct require_same;
|
||||
template<typename T> struct require_same<T, T> { using type = void; };
|
||||
|
||||
template<typename T, typename U>
|
||||
typename require_same<T, U>::type
|
||||
check_type(U&) { }
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
std::shared_ptr<long> s;
|
||||
std::weak_ptr w(s);
|
||||
check_type<std::weak_ptr<long>>(w);
|
||||
|
||||
std::weak_ptr w2(w);
|
||||
check_type<std::weak_ptr<long>>(w2);
|
||||
}
|
46
libstdc++-v3/testsuite/23_containers/array/cons/deduction.cc
Normal file
46
libstdc++-v3/testsuite/23_containers/array/cons/deduction.cc
Normal file
|
@ -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
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
// { dg-do compile { target c++1z } }
|
||||
|
||||
#include <array>
|
||||
|
||||
template<typename T, typename U> struct require_same;
|
||||
template<typename T> struct require_same<T, T> { using type = void; };
|
||||
|
||||
template<typename T, typename U>
|
||||
typename require_same<T, U>::type
|
||||
check_type(U&) { }
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
std::array a1{ 1, 2, 3 };
|
||||
check_type<std::array<int, 3>>(a1);
|
||||
int y = 2;
|
||||
const int z = 3;
|
||||
std::array a2{ 1, y, z };
|
||||
check_type<std::array<int, 3>>(a2);
|
||||
std::array a3{ 'a', 'b', 'c', 'd', 'e' };
|
||||
check_type<std::array<char, 5>>(a3);
|
||||
|
||||
std::array copy = a1;
|
||||
check_type<decltype(a1)>(copy);
|
||||
std::array move = std::move(a1);
|
||||
check_type<decltype(a1)>(move);
|
||||
}
|
|
@ -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
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
// { dg-do compile { target c++1z } }
|
||||
|
||||
#include <array>
|
||||
|
||||
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 }
|
|
@ -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 }
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -22,4 +22,4 @@
|
|||
|
||||
typedef std::tuple_element<1, std::array<int, 1>>::type type;
|
||||
|
||||
// { dg-error "static assertion failed" "" { target *-*-* } 350 }
|
||||
// { dg-error "static assertion failed" "" { target *-*-* } 357 }
|
||||
|
|
42
libstdc++-v3/testsuite/26_numerics/valarray/deduction.cc
Normal file
42
libstdc++-v3/testsuite/26_numerics/valarray/deduction.cc
Normal file
|
@ -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
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
// { dg-do compile { target c++1z } }
|
||||
|
||||
#include <valarray>
|
||||
|
||||
template<typename T, typename U> struct require_same;
|
||||
template<typename T> struct require_same<T, T> { using type = void; };
|
||||
|
||||
template<typename T, typename U>
|
||||
typename require_same<T, U>::type
|
||||
check_type(U&) { }
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
int arr[4] = { 1, 2, 3, 4 };
|
||||
std::valarray v(arr, 4);
|
||||
check_type<std::valarray<int>>(v);
|
||||
|
||||
std::valarray v2 = v;
|
||||
check_type<std::valarray<int>>(v2);
|
||||
|
||||
std::valarray v3 = std::move(v);
|
||||
check_type<std::valarray<int>>(v3);
|
||||
}
|
|
@ -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
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
// { dg-do compile { target c++1z } }
|
||||
|
||||
#include <mutex>
|
||||
|
||||
template<typename T, typename U> struct require_same;
|
||||
template<typename T> struct require_same<T, T> { using type = void; };
|
||||
|
||||
template<typename T, typename U>
|
||||
typename require_same<T, U>::type
|
||||
check_type(U&) { }
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
std::mutex m;
|
||||
std::lock_guard l(m);
|
||||
check_type<std::lock_guard<std::mutex>>(l);
|
||||
|
||||
struct Mutex {
|
||||
void lock() { }
|
||||
void unlock() { }
|
||||
} m2;
|
||||
|
||||
std::lock_guard l2(m2);
|
||||
check_type<std::lock_guard<Mutex>>(l2);
|
||||
}
|
|
@ -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
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
// { dg-do compile { target c++1z } }
|
||||
|
||||
#include <mutex>
|
||||
|
||||
template<typename T, typename U> struct require_same;
|
||||
template<typename T> struct require_same<T, T> { using type = void; };
|
||||
|
||||
template<typename T, typename U>
|
||||
typename require_same<T, U>::type
|
||||
check_type(U&) { }
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
std::scoped_lock l0;
|
||||
check_type<std::scoped_lock<>>(l0);
|
||||
|
||||
struct BasicLockable {
|
||||
void lock() { }
|
||||
void unlock() { }
|
||||
} m1;
|
||||
|
||||
std::scoped_lock l1(m1);
|
||||
check_type<std::scoped_lock<BasicLockable>>(l1);
|
||||
|
||||
struct Lockable {
|
||||
void lock() { }
|
||||
void unlock() { }
|
||||
bool try_lock() { return true; }
|
||||
} m2;
|
||||
|
||||
std::mutex m3;
|
||||
std::scoped_lock l2(m2, m3);
|
||||
check_type<std::scoped_lock<Lockable, std::mutex>>(l2);
|
||||
}
|
|
@ -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
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
// { dg-do compile { target c++1z } }
|
||||
|
||||
#include <mutex>
|
||||
|
||||
template<typename T, typename U> struct require_same;
|
||||
template<typename T> struct require_same<T, T> { using type = void; };
|
||||
|
||||
template<typename T, typename U>
|
||||
typename require_same<T, U>::type
|
||||
check_type(U&) { }
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
std::mutex m;
|
||||
std::unique_lock l(m);
|
||||
check_type<std::unique_lock<std::mutex>>(l);
|
||||
|
||||
struct Mutex {
|
||||
void lock() { }
|
||||
void unlock() { }
|
||||
} m2;
|
||||
|
||||
std::unique_lock l2(m2);
|
||||
check_type<std::unique_lock<Mutex>>(l2);
|
||||
}
|
Loading…
Add table
Reference in a new issue