]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR libstdc++/87538 fix std::not_fn exception specifications
authorJonathan Wakely <jwakely@redhat.com>
Mon, 8 Oct 2018 13:13:06 +0000 (14:13 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 8 Oct 2018 13:13:06 +0000 (14:13 +0100)
Backport from mainline
2018-10-08  Jonathan Wakely  <jwakely@redhat.com>

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.
* testsuite/experimental/functional/87538.cc: New test.

From-SVN: r264926

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/functional
libstdc++-v3/testsuite/20_util/function_objects/not_fn/87538.cc [new file with mode: 0644]
libstdc++-v3/testsuite/experimental/functional/87538.cc [new file with mode: 0644]

index d715425e7cc6370798710c4beb355ec9d4374fd8..922e0426080066064ab2bd2c5fb753dcf43dbb35 100644 (file)
@@ -1,3 +1,14 @@
+2018-10-08  Jonathan Wakely  <jwakely@redhat.com>
+
+       Backport from mainline
+       2018-10-08  Jonathan Wakely  <jwakely@redhat.com>
+
+       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.
+       * testsuite/experimental/functional/87538.cc: New test.
+
 2018-08-13  Jonathan Wakely  <jwakely@redhat.com>
 
        Revert
index 465b3ec7792de5a969b012f42cbc983b8896a6dc..edf6f10661104b03855214e676d8daeb3920d3a5 100644 (file)
@@ -931,7 +931,8 @@ _GLIBCXX_MEM_FN_TRAITS(&& noexcept, false_type, true_type)
       template<typename... _Args>                                      \
        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 (file)
index 0000000..ade996d
--- /dev/null
@@ -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
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do run { target c++1z } }
+
+#include <functional>
+#include <testsuite_hooks.h>
+
+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();
+}
diff --git a/libstdc++-v3/testsuite/experimental/functional/87538.cc b/libstdc++-v3/testsuite/experimental/functional/87538.cc
new file mode 100644 (file)
index 0000000..1ee9ecd
--- /dev/null
@@ -0,0 +1,48 @@
+// 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
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do run { target c++14 } }
+
+#include <experimental/functional>
+#include <testsuite_hooks.h>
+
+struct N {
+  int operator()(int i) { if (i == 0) throw -1; return i; }
+};
+
+void
+test01()
+{
+  N n;
+  auto not_n = std::experimental::not_fn(n);
+  static_assert( !noexcept(not_n(1)), "can throw" );
+  VERIFY(not_n(1) == 0);
+  int exception = 0;
+  try {
+    not_n(0);
+  }
+  catch (int e) {
+    exception = e;
+  }
+  VERIFY(exception == -1);
+}
+
+int
+main()
+{
+  test01();
+}