PR libstdc++/83395 fix invocable traits for INVOKE<cv void>
authorJonathan Wakely <jwakely@redhat.com>
Tue, 12 Dec 2017 17:42:19 +0000 (17:42 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 12 Dec 2017 17:42:19 +0000 (17:42 +0000)
PR libstdc++/83395
* include/std/type_traits (__is_invocable_impl): Remove partial
specialization for INVOKE<void> and restore is_void<R> check in
primary template.
(__is_nt_invocable_impl): Likewise.
* testsuite/20_util/is_invocable/83395.cc: New test.
* testsuite/20_util/is_nothrow_invocable/83395.cc: New test.

From-SVN: r255584

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/type_traits
libstdc++-v3/testsuite/20_util/is_invocable/83395.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/is_nothrow_invocable/83395.cc [new file with mode: 0644]

index 3043c25356561bc063ff4d7865494bfca0054595..c8c93350a608379203e9b859ddbed0a400eb0a77 100644 (file)
@@ -1,3 +1,13 @@
+2017-12-12  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR libstdc++/83395
+       * include/std/type_traits (__is_invocable_impl): Remove partial
+       specialization for INVOKE<void> and restore is_void<R> check in
+       primary template.
+       (__is_nt_invocable_impl): Likewise.
+       * testsuite/20_util/is_invocable/83395.cc: New test.
+       * testsuite/20_util/is_nothrow_invocable/83395.cc: New test.
+
 2017-12-07  David Edelsohn  <dje.gcc@gmail.com>
 
        PR libstdc++/83120
index 1d639e452f324452682637c9dc7485ea20987a26..3d94566fa6313236f7488e215784fabd914ccd3d 100644 (file)
@@ -2589,12 +2589,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template<typename _Result, typename _Ret>
     struct __is_invocable_impl<_Result, _Ret, __void_t<typename _Result::type>>
-    : is_convertible<typename _Result::type, _Ret>::type
-    { };
-
-  template<typename _Result>
-    struct __is_invocable_impl<_Result, void, __void_t<typename _Result::type>>
-    : true_type
+    : __or_<is_void<_Ret>, is_convertible<typename _Result::type, _Ret>>::type
     { };
 
   template<typename _Fn, typename... _ArgTypes>
@@ -2699,14 +2694,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Result, typename _Ret>
     struct __is_nt_invocable_impl<_Result, _Ret,
                                  __void_t<typename _Result::type>>
-    : __and_<is_convertible<typename _Result::type, _Ret>,
-            is_nothrow_constructible<_Ret, typename _Result::type>>
-    { };
-
-  template<typename _Result>
-    struct __is_nt_invocable_impl<_Result, void,
-                                 __void_t<typename _Result::type>>
-    : true_type
+    : __or_<is_void<_Ret>,
+           __and_<is_convertible<typename _Result::type, _Ret>,
+                  is_nothrow_constructible<_Ret, typename _Result::type>>>
     { };
 
   /// std::is_nothrow_invocable_r
diff --git a/libstdc++-v3/testsuite/20_util/is_invocable/83395.cc b/libstdc++-v3/testsuite/20_util/is_invocable/83395.cc
new file mode 100644 (file)
index 0000000..7fb1368
--- /dev/null
@@ -0,0 +1,28 @@
+// 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++17 } }
+
+#include <type_traits>
+
+// PR libstdc++/83395
+using F = int(*)();
+static_assert(std::is_invocable_r<void, F>::value);
+static_assert(std::is_invocable_r<void const, F>::value);
+static_assert(std::is_invocable_r<void volatile, F>::value);
+static_assert(std::is_invocable_r<void const volatile, F>::value);
diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/83395.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/83395.cc
new file mode 100644 (file)
index 0000000..2a253df
--- /dev/null
@@ -0,0 +1,28 @@
+// 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++17 } }
+
+#include <type_traits>
+
+// PR libstdc++/83395
+using F = int(*)() noexcept;
+static_assert(std::is_nothrow_invocable_r<void, F>::value);
+static_assert(std::is_nothrow_invocable_r<void const, F>::value);
+static_assert(std::is_nothrow_invocable_r<void volatile, F>::value);
+static_assert(std::is_nothrow_invocable_r<void const volatile, F>::value);