From patchwork Wed Mar 22 16:00:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 742164 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vpDtf2Rwgz9s7B for ; Thu, 23 Mar 2017 03:00:58 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ltUNW/xd"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=G4i7DOG1+i1awcfiJgKC9mpiPRb1cirwwTnWJ0Cc7OZBpT2nP2Jid LlZsxIwFM0aSeQkCX8pBHwp0ji8y70wz8wz8sXBt82Grpr5U1QG+NjTND0ZR4rCw jIaN53VOOFKCl6oi+p86wEOAaFCqMTRq8IC5zxpX2Qi4mipQZRG4MU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=UdP/39Hwb7jGbAlYKKvznmwT0kM=; b=ltUNW/xdVhbHtkBZqYnN zq4dbrj+QlSGFuMMHIZ97ELWjO/h/B9EK1lvT4F/rGcno7svScBJGcNAs5XgJ7qq JebcyTAp5uEfw2rgQJNg/ut5OR3705UfWJlaujigBOHAXpMObR/omNOyjR5/Cnu4 3uMHvO69f4HP6CfVFKxWU9k= Received: (qmail 102476 invoked by alias); 22 Mar 2017 16:00:46 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 102420 invoked by uid 89); 22 Mar 2017 16:00:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=302, sk:jwakely, Wakely, wakely X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 22 Mar 2017 16:00:36 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C7F0067EA7; Wed, 22 Mar 2017 16:00:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C7F0067EA7 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jwakely@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C7F0067EA7 Received: from localhost (unknown [10.33.36.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F0C17E626; Wed, 22 Mar 2017 16:00:36 +0000 (UTC) Date: Wed, 22 Mar 2017 16:00:34 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] Add deduction guides for C++17 (P0433R2, partial) Message-ID: <20170322160034.GA29525@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.8.0 (2017-02-23) This adds some of the C++17 deduction guides, all except for the allocator-aware containers and basic_regex. I have patches adding those guide too, but am still working on the tests (some cases I expected to work are ill-formed, so I'm still looking into why). * 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. Tested powerpc64le-linux, comitted to trunk. commit beffaa9ede39cc8b9993685caa8820c1fc55382b Author: Jonathan Wakely Date: Wed Mar 22 15:37:23 2017 +0000 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. diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index 851f9cf..fe933ff 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 7d77e21..b393a94 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 e5e9f1c..66f52b3 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 3ff786a..9c27922 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 261f2af..1c7d6dc 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 ae5bc0a..3db10ca 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 f53daf1..ae495d9 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 ad50650..2dc6e42 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 0000000..a4346e0 --- /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 0506ea4..9cc1455 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.cc b/libstdc++-v3/testsuite/20_util/optional/cons/deduction.cc new file mode 100644 index 0000000..e15db0b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/optional/cons/deduction.cc @@ -0,0 +1,49 @@ +// 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 } + +#include +#include + +struct MoveOnly +{ + MoveOnly() = default; + MoveOnly(MoveOnly&&) {} + MoveOnly& operator=(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 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/optional/cons/deduction_guide.cc b/libstdc++-v3/testsuite/20_util/optional/cons/deduction_guide.cc deleted file mode 100644 index 59698dc..0000000 --- a/libstdc++-v3/testsuite/20_util/optional/cons/deduction_guide.cc +++ /dev/null @@ -1,44 +0,0 @@ -// { 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 -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -#include -#include - -struct MoveOnly -{ - MoveOnly() = default; - MoveOnly(MoveOnly&&) {} - MoveOnly& operator=(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(); -} 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 0000000..c8e6fd6 --- /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 0000000..ecd0780 --- /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 0000000..47e2488 --- /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 0dc62a2..03835f4 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 0000000..23aca62 --- /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 0000000..ea38417 --- /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 0000000..5ce2909 --- /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 0000000..ec11b05 --- /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 03d284b..81d8b93 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 0b9ca95..8983ad7 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 c6a8d00..493449a 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 0000000..72d4bc0 --- /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 0000000..b72c1a1 --- /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 0000000..399de7a --- /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 0000000..4f36bab --- /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); +}