+2019-08-20 Jonathan Wakely <jwakely@redhat.com>
+
+ PR libstdc++/91371
+ * include/std/type_traits (is_function): Simplify definition. Remove
+ partial specializations for function types.
+ (__is_referenceable): Simplify definition.
+ * testsuite/20_util/bind/91371.cc: New test.
+ * testsuite/20_util/is_function/91371.cc: New test.
+ * testsuite/20_util/is_function/value.cc: Check more pointer types.
+ * testsuite/20_util/is_member_function_pointer/91371.cc: New test.
+ * testsuite/20_util/is_object/91371.cc: New test.
+
2019-08-16 Uros Bizjak <ubizjak@gmail.com>
* config/abi/post/alpha-linux-gnu/baseline_symbols.txt: Update.
struct __failure_type
{ };
- // Primary type categories.
-
template<typename>
struct remove_cv;
+ template<typename>
+ struct is_const;
+
+ // Primary type categories.
+
template<typename>
struct __is_void_helper
: public false_type { };
{ };
/// is_function
- template<typename>
+ template<typename _Tp>
struct is_function
- : public false_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes...) _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes...) & _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes...) && _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes......) _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes......) & _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes......) && _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes...) const _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes...) const & _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes...) const && _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
+ : public __bool_constant<!is_const<const _Tp>::value> { };
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes......) const _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes......) const & _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes......) const && _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes...) volatile _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes...) volatile & _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes...) volatile && _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes......) volatile _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes......) volatile & _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes......) volatile && _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes...) const volatile _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes...) const volatile & _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes...) const volatile && _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes......) const volatile _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
-
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes......) const volatile & _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
+ template<typename _Tp>
+ struct is_function<_Tp&>
+ : public false_type { };
- template<typename _Res, typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
- struct is_function<_Res(_ArgTypes......) const volatile && _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type { };
+ template<typename _Tp>
+ struct is_function<_Tp&&>
+ : public false_type { };
#define __cpp_lib_is_null_pointer 201309
>;
+ // __void_t (std::void_t for C++11)
+ template<typename...> using __void_t = void;
+
// Utility to detect referenceable types ([defns.referenceable]).
- template<typename _Tp>
+ template<typename _Tp, typename = void>
struct __is_referenceable
- : public __or_<is_object<_Tp>, is_reference<_Tp>>::type
- { };
-
- template<typename _Res, typename... _Args _GLIBCXX_NOEXCEPT_PARM>
- struct __is_referenceable<_Res(_Args...) _GLIBCXX_NOEXCEPT_QUAL>
- : public true_type
+ : public false_type
{ };
- template<typename _Res, typename... _Args _GLIBCXX_NOEXCEPT_PARM>
- struct __is_referenceable<_Res(_Args......) _GLIBCXX_NOEXCEPT_QUAL>
+ template<typename _Tp>
+ struct __is_referenceable<_Tp, __void_t<_Tp&>>
: public true_type
{ };
struct conditional<false, _Iftrue, _Iffalse>
{ typedef _Iffalse type; };
- // __void_t (std::void_t for C++11)
- template<typename...> using __void_t = void;
-
/// common_type
template<typename... _Tp>
struct common_type;
--- /dev/null
+// Copyright (C) 2019 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 compile { target i?86-*-* x86_64-*-* } }
+// { dg-require-effective-target c++11 }
+
+#include <functional>
+
+int bar(int) __attribute__((ms_abi));
+int baz(int) __attribute__((sysv_abi));
+
+void
+test01()
+{
+ // PR libstdc++/91371
+ std::bind(bar, 5)();
+ std::bind(baz, 5)();
+
+ static_assert(std::is_function<decltype(bar)>::value, "");
+ static_assert(std::is_function<decltype(baz)>::value, "");
+ static_assert(std::is_pointer<std::decay_t<decltype(bar)>>::value, "");
+ static_assert(std::is_pointer<std::decay_t<decltype(baz)>>::value, "");
+}
--- /dev/null
+// Copyright (C) 2019 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 compile { target i?86-*-* x86_64-*-* } }
+// { dg-require-effective-target c++11 }
+
+#include <type_traits>
+
+using std::is_function;
+
+#ifdef __i386__
+static_assert(is_function<void __attribute__((thiscall)) ()>::value, "");
+static_assert(is_function<void __attribute__((thiscall)) () const>::value, "");
+static_assert(is_function<void __attribute__((fastcall)) ()>::value, "");
+static_assert(is_function<void __attribute__((fastcall)) () const>::value, "");
+static_assert(is_function<void __attribute__((stdcall)) ()>::value, "");
+static_assert(is_function<void __attribute__((stdcall)) () const>::value, "");
+#endif
+static_assert(is_function<void __attribute__((ms_abi)) ()>::value, "");
+static_assert(is_function<void __attribute__((ms_abi)) () const>::value, "");
+static_assert(is_function<void __attribute__((ms_abi)) () const &>::value, "");
+static_assert(is_function<void __attribute__((ms_abi)) () &&>::value, "");
+static_assert(is_function<void __attribute__((sysv_abi)) ()>::value, "");
+static_assert(is_function<void __attribute__((sysv_abi)) () const>::value, "");
+
+struct X { operator X*(); };
+static_assert(!is_function<X>::value, "");
+static_assert(!is_function<X&>::value, "");
+static_assert(!is_function<X*>::value, "");
+union Y { operator Y*(); int i; long l;};
+static_assert(!is_function<Y>::value, "");
+static_assert(!is_function<Y&>::value, "");
+static_assert(!is_function<Y*>::value, "");
char (int, ClassType) const volatile &&>(true), "");
// Negative tests.
+ static_assert(test_category<is_function, int*>(false), "");
static_assert(test_category<is_function, int&>(false), "");
static_assert(test_category<is_function, void>(false), "");
static_assert(test_category<is_function, const void>(false), "");
+ static_assert(test_category<is_function, void*>(false), "");
+ static_assert(test_category<is_function, const void*>(false), "");
+ static_assert(test_category<is_function, void**>(false), "");
+ static_assert(test_category<is_function, std::nullptr_t>(false), "");
static_assert(test_category<is_function, AbstractClass>(false), "");
static_assert(test_category<is_function, int(&)(int)>(false), "");
+ static_assert(test_category<is_function, int(*)(int)>(false), "");
// Sanity check.
static_assert(test_category<is_function, ClassType>(false), "");
--- /dev/null
+// Copyright (C) 2019 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 compile { target i?86-*-* x86_64-*-* } }
+// { dg-require-effective-target c++11 }
+
+#include <type_traits>
+
+struct Z
+{
+ void __attribute__((ms_abi)) f() const { }
+ void __attribute__((sysv_abi)) g() const { }
+#ifdef __i386__
+ void __attribute__((thiscall)) h() const { }
+#endif
+};
+static_assert( std::is_member_function_pointer<decltype(&Z::f)>::value, "" );
+static_assert( std::is_member_function_pointer<decltype(&Z::g)>::value, "" );
+#ifdef __i386__
+static_assert( std::is_member_function_pointer<decltype(&Z::h)>::value, "" );
+#endif
--- /dev/null
+// Copyright (C) 2019 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 compile { target i?86-*-* x86_64-*-* } }
+// { dg-require-effective-target c++11 }
+
+#include <type_traits>
+
+using std::is_object;
+
+#ifdef __i386__
+static_assert(!is_object<void __attribute__((thiscall)) ()>::value, "");
+static_assert(!is_object<void __attribute__((thiscall)) () const>::value, "");
+static_assert(!is_object<void __attribute__((fastcall)) ()>::value, "");
+static_assert(!is_object<void __attribute__((fastcall)) () const>::value, "");
+static_assert(!is_object<void __attribute__((stdcall)) ()>::value, "");
+static_assert(!is_object<void __attribute__((stdcall)) () const>::value, "");
+#endif
+static_assert(!is_object<void __attribute__((ms_abi)) ()>::value, "");
+static_assert(!is_object<void __attribute__((ms_abi)) () const>::value, "");
+static_assert(!is_object<void __attribute__((ms_abi)) () const &>::value, "");
+static_assert(!is_object<void __attribute__((ms_abi)) () &&>::value, "");
+static_assert(!is_object<void __attribute__((sysv_abi)) ()>::value, "");
+static_assert(!is_object<void __attribute__((sysv_abi)) () const>::value, "");