From 606f6be67bfc5b533d72d83063e184b6df0e125f Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 8 Oct 2018 13:07:22 +0100 Subject: [PATCH] PR libstdc++/87538 fix std::not_fn exception specifications PR libstdc++/87538 * include/std/functional (_Not_fn::operator()): Check value of __is_nothrow_invocable as well. * testsuite/20_util/function_objects/not_fn/87538.cc: New test. From-SVN: r264921 --- libstdc++-v3/ChangeLog | 7 +++ libstdc++-v3/include/std/functional | 3 +- .../20_util/function_objects/not_fn/87538.cc | 49 +++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 libstdc++-v3/testsuite/20_util/function_objects/not_fn/87538.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e812b34d1d0..aec162913c2 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2018-10-08 Jonathan Wakely + + PR libstdc++/87538 + * include/std/functional (_Not_fn::operator()): Check value of + __is_nothrow_invocable as well. + * testsuite/20_util/function_objects/not_fn/87538.cc: New test. + 2018-10-08 François Dumont * include/debug/list (list<>::cbegin()): Use C++11 direct diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index 2b46ba899dd..093528bcc4f 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -864,7 +864,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template \ decltype(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>()) \ operator()(_Args&&... __args) _QUALS \ - noexcept(noexcept(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>())) \ + noexcept(__is_nothrow_invocable<_Fn _QUALS, _Args...>::value \ + && noexcept(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>())) \ { \ return !std::__invoke(std::forward< _Fn _QUALS >(_M_fn), \ std::forward<_Args>(__args)...); \ diff --git a/libstdc++-v3/testsuite/20_util/function_objects/not_fn/87538.cc b/libstdc++-v3/testsuite/20_util/function_objects/not_fn/87538.cc new file mode 100644 index 00000000000..7f4f0df54ae --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function_objects/not_fn/87538.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2018 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 run { target c++17 } } + +#include +#include + +struct N { + int operator()(int i) { if (i == 0) throw -1; return i; } +}; + +void +test01() +{ + N n; + auto not_n = std::not_fn(n); + static_assert( !noexcept(not_n(1)) ); + VERIFY(not_n(1) == 0); + int exception = 0; + try { + not_n(0); + } + catch (int e) { + exception = e; + } + VERIFY(exception == -1); +} + +int +main() +{ + test01(); +}