From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id 072393890436; Fri, 24 Jul 2020 13:11:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 072393890436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1595596302; bh=5VC5BA74J8Rv34vRxVOXyqK+VT1HV3+25y8ks2cvCZA=; h=From:To:Subject:Date:From; b=OQcWmRVRSv12IEJmX2HBZphjcUXYRnULCsBQMMgf9G3IFIO9ja1KK1cF4Obl9QOYO F8cHBVdksSJC/Uepmo8muleSLS1NNWriGwaKsbyfj4KHYYl4IqSI/mjUU1PCCO8fbG 98ta0YdL0eOzAKfI6vC+htogb0n3kzuBXtJin28g= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Alexandre Oliva To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc(refs/users/aoliva/heads/testbase)] libstdc++: Add static assertions to futures and promises [LWG 3458] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/users/aoliva/heads/testbase X-Git-Oldrev: e55ba804d3b8de86a430a8a5553dfc1ad06daa74 X-Git-Newrev: 1f53367fb5f16985e82c39f56368b956292cf86c Message-Id: <20200724131142.072393890436@sourceware.org> Date: Fri, 24 Jul 2020 13:11:42 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jul 2020 13:11:42 -0000 https://gcc.gnu.org/g:1f53367fb5f16985e82c39f56368b956292cf86c commit 1f53367fb5f16985e82c39f56368b956292cf86c Author: Jonathan Wakely Date: Wed Jul 22 20:10:38 2020 +0100 libstdc++: Add static assertions to futures and promises [LWG 3458] LWG recently decided it should be ill-formed to instantiate std::future and std::shared_future for types that can't be returned from a function. This adds static assertions to enforce it (std::future already failed, but this makes the error more understandable). LWG 3466 extends that to std::promise. The actual constraint is that t.~T() is well-formed for the primary template, but rejecting arrays and functions as done for futures matches that condition. libstdc++-v3/ChangeLog: * include/std/future (future, shared_future, promise): Add static assertions to the primary template to reject array and function types. * testsuite/30_threads/future/requirements/lwg3458.cc: New test. * testsuite/30_threads/promise/requirements/lwg3466.cc: New test. * testsuite/30_threads/shared_future/requirements/lwg3458.cc: New test. Diff: --- libstdc++-v3/include/std/future | 15 ++++++++++ .../30_threads/future/requirements/lwg3458.cc | 34 ++++++++++++++++++++++ .../30_threads/promise/requirements/lwg3466.cc | 34 ++++++++++++++++++++++ .../shared_future/requirements/lwg3458.cc | 32 ++++++++++++++++++++ 4 files changed, 115 insertions(+) diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future index 6eef6864f4d..bdf4a75d694 100644 --- a/libstdc++-v3/include/std/future +++ b/libstdc++-v3/include/std/future @@ -763,6 +763,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template class future : public __basic_future<_Res> { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3458. Is shared_future intended to work with arrays or function types? + static_assert(!is_array<_Res>{}, "result type is not an array"); + static_assert(!is_function<_Res>{}, "result type is not a function"); + friend class promise<_Res>; template friend class packaged_task; template @@ -893,6 +898,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template class shared_future : public __basic_future<_Res> { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3458. Is shared_future intended to work with arrays or function types? + static_assert(!is_array<_Res>{}, "result type is not an array"); + static_assert(!is_function<_Res>{}, "result type is not a function"); + typedef __basic_future<_Res> _Base_type; public: @@ -1045,6 +1055,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template class promise { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3466: Specify the requirements for promise/future/[...] consistently + static_assert(!is_array<_Res>{}, "result type is not an array"); + static_assert(!is_function<_Res>{}, "result type is not a function"); + typedef __future_base::_State_base _State; typedef __future_base::_Result<_Res> _Res_type; typedef __future_base::_Ptr<_Res_type> _Ptr_type; diff --git a/libstdc++-v3/testsuite/30_threads/future/requirements/lwg3458.cc b/libstdc++-v3/testsuite/30_threads/future/requirements/lwg3458.cc new file mode 100644 index 00000000000..2bc206c9450 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/future/requirements/lwg3458.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2020 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-do compile { target c++11 } } + +// LWG 3458 +// Is shared_future intended to work with arrays or function types? + +#include + +std::future good; +std::future good2; + +std::future bad; // { dg-error "here" } +// { dg-error "result type is not an array" "" { target *-*-* } 0 } +// { dg-prune-output "function returning an array" } + +std::future bad2; // { dg-error "here" } +// { dg-error "result type is not a function" "" { target *-*-* } 0 } +// { dg-prune-output "function returning a function" } diff --git a/libstdc++-v3/testsuite/30_threads/promise/requirements/lwg3466.cc b/libstdc++-v3/testsuite/30_threads/promise/requirements/lwg3466.cc new file mode 100644 index 00000000000..124c86c0392 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/requirements/lwg3466.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2020 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-do compile { target c++11 } } + +// LWG 3466 +// Specify the requirements for promise/future/shared_future consistently + +#include + +std::promise good; +std::promise good2; + +std::promise bad; // { dg-error "here" } +// { dg-error "result type is not an array" "" { target *-*-* } 0 } +// { dg-prune-output {request for member '~int \[1\]'} } + +std::promise bad2; // { dg-error "here" } +// { dg-error "result type is not a function" "" { target *-*-* } 0 } +// { dg-prune-output {'sizeof \(int\(\)\)'} } diff --git a/libstdc++-v3/testsuite/30_threads/shared_future/requirements/lwg3458.cc b/libstdc++-v3/testsuite/30_threads/shared_future/requirements/lwg3458.cc new file mode 100644 index 00000000000..df5bfd2b976 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/shared_future/requirements/lwg3458.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2020 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-do compile { target c++11 } } + +// LWG 3458 +// Is shared_future intended to work with arrays or function types? + +#include + +std::shared_future good; +std::shared_future good2; + +std::shared_future bad; // { dg-error "here" } +// { dg-error "result type is not an array" "" { target *-*-* } 0 } + +std::shared_future bad2; // { dg-error "here" } +// { dg-error "result type is not a function" "" { target *-*-* } 0 }