public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/2] c++, libstdc++: implement __is_scalar built-in trait
@ 2023-07-03  9:13 Ken Matsui
  2023-07-03  9:13 ` [PATCH 2/2] libstdc++: use new built-in trait __is_scalar for std::is_scalar Ken Matsui
  2023-07-03 10:00 ` [PATCH 1/2] c++, libstdc++: implement __is_scalar built-in trait Ken Matsui
  0 siblings, 2 replies; 12+ messages in thread
From: Ken Matsui @ 2023-07-03  9:13 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++, Ken Matsui

This patch implements built-in trait for std::is_scalar. The existent
__is_scalar codes were replaced with ____is_scalar to avoid unintentional
macro replacement by the new built-in.

gcc/cp/ChangeLog:

	* cp-trait.def: Define __is_scalar.
	* constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SCALAR.
	* semantics.cc (trait_expr_value): Likewise.
	(finish_trait_expr): Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/ext/has-builtin-1.C: Test existence of __is_scalar.
	* g++.dg/ext/is_scalar.C: New test.
	* g++.dg/tm/pr46567.C: Use ____is_scalar instead.
	* g++.dg/torture/pr57107.C: Likewise.

libstdc++-v3/ChangeLog:

	* include/bits/cpp_type_traits.h (__is_scalar): Rename to ...
	(____is_scalar): ... this.
	* include/bits/stl_algobase.h: Use ____is_scalar instead.
	* include/bits/valarray_array.h: Likewise.

Signed-off-by: Ken Matsui <kmatsui@cs.washington.edu>
---
 gcc/cp/constraint.cc                        |  3 ++
 gcc/cp/cp-trait.def                         |  1 +
 gcc/cp/semantics.cc                         |  4 +++
 gcc/testsuite/g++.dg/ext/has-builtin-1.C    |  3 ++
 gcc/testsuite/g++.dg/ext/is_scalar.C        | 31 +++++++++++++++++++++
 gcc/testsuite/g++.dg/tm/pr46567.C           | 10 +++----
 gcc/testsuite/g++.dg/torture/pr57107.C      |  4 +--
 libstdc++-v3/include/bits/cpp_type_traits.h |  2 +-
 libstdc++-v3/include/bits/stl_algobase.h    |  8 +++---
 libstdc++-v3/include/bits/valarray_array.h  |  2 +-
 10 files changed, 55 insertions(+), 13 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/is_scalar.C

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 8cf0f2d0974..4c27f2a3a62 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3751,6 +3751,9 @@ diagnose_trait_expr (tree expr, tree args)
     case CPTK_IS_UNION:
       inform (loc, "  %qT is not a union", t1);
       break;
+    case CPTK_IS_SCALAR:
+      inform (loc, "  %qT is not a scalar type", t1);
+      break;
     case CPTK_IS_AGGREGATE:
       inform (loc, "  %qT is not an aggregate", t1);
       break;
diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
index 8b7fece0cc8..59ae087c457 100644
--- a/gcc/cp/cp-trait.def
+++ b/gcc/cp/cp-trait.def
@@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2)
 DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1)
 DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1)
 DEFTRAIT_EXPR (IS_UNION, "__is_union", 1)
+DEFTRAIT_EXPR (IS_SCALAR, "__is_scalar", 1)
 DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2)
 DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2)
 /* FIXME Added space to avoid direct usage in GCC 13.  */
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 8fb47fd179e..3edc7f23212 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12118,6 +12118,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
     case CPTK_IS_UNION:
       return type_code1 == UNION_TYPE;
 
+    case CPTK_IS_SCALAR:
+      return SCALAR_TYPE_P (type1);
+
     case CPTK_IS_ASSIGNABLE:
       return is_xible (MODIFY_EXPR, type1, type2);
 
@@ -12296,6 +12299,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2)
     case CPTK_IS_ENUM:
     case CPTK_IS_UNION:
     case CPTK_IS_SAME:
+    case CPTK_IS_SCALAR:
       break;
 
     case CPTK_IS_LAYOUT_COMPATIBLE:
diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
index f343e153e56..75acbdfb9fc 100644
--- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
+++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
@@ -146,3 +146,6 @@
 #if !__has_builtin (__remove_cvref)
 # error "__has_builtin (__remove_cvref) failed"
 #endif
+#if !__has_builtin (__is_scalar)
+# error "__has_builtin (__is_scalar) failed"
+#endif
diff --git a/gcc/testsuite/g++.dg/ext/is_scalar.C b/gcc/testsuite/g++.dg/ext/is_scalar.C
new file mode 100644
index 00000000000..457fddc52fc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_scalar.C
@@ -0,0 +1,31 @@
+// { dg-do compile { target c++11 } }
+
+#include <cstddef>  // std::nullptr_t
+#include <testsuite_tr1.h>
+
+using namespace __gnu_test;
+
+#define SA(X) static_assert((X),#X)
+
+#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT)	\
+  SA(TRAIT(TYPE) == EXPECT);					\
+  SA(TRAIT(const TYPE) == EXPECT);				\
+  SA(TRAIT(volatile TYPE) == EXPECT);			\
+  SA(TRAIT(const volatile TYPE) == EXPECT)
+
+// volatile return type would cause a warning.
+#define SA_FN_TEST_CATEGORY(TRAIT, TYPE, EXPECT)	\
+  SA(TRAIT(TYPE) == EXPECT);						\
+  SA(TRAIT(const TYPE) == EXPECT)
+
+SA_TEST_CATEGORY(__is_scalar, int, true);
+SA_TEST_CATEGORY(__is_scalar, float, true);
+SA_TEST_CATEGORY(__is_scalar, EnumType, true);
+SA_TEST_CATEGORY(__is_scalar, int*, true);
+SA_FN_TEST_CATEGORY(__is_scalar, int(*)(int), true);
+SA_TEST_CATEGORY(__is_scalar, int (ClassType::*), true);
+SA_FN_TEST_CATEGORY(__is_scalar, int (ClassType::*) (int), true);
+SA_TEST_CATEGORY(__is_scalar, std::nullptr_t, true);
+
+// Sanity check.
+SA_TEST_CATEGORY(__is_scalar, ClassType, false);
diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C
index 6d791484448..d79e0afb462 100644
--- a/gcc/testsuite/g++.dg/tm/pr46567.C
+++ b/gcc/testsuite/g++.dg/tm/pr46567.C
@@ -225,7 +225,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
     : public __traitor<__is_void<_Tp>, __is_arithmetic<_Tp> >
     { };
   template<typename _Tp>
-    struct __is_scalar
+    struct ____is_scalar
     : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >
     { };
   template<typename _Tp>
@@ -1325,7 +1325,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
     }
   template<typename _ForwardIterator, typename _Tp>
     inline typename
-    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, void>::__type
+    __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, void>::__type
     __fill_a(_ForwardIterator __first, _ForwardIterator __last,
        const _Tp& __value)
     {
@@ -1334,7 +1334,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
     }
   template<typename _ForwardIterator, typename _Tp>
     inline typename
-    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type
+    __gnu_cxx::__enable_if<____is_scalar<_Tp>::__value, void>::__type
     __fill_a(_ForwardIterator __first, _ForwardIterator __last,
       const _Tp& __value)
     {
@@ -1362,7 +1362,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
     }
   template<typename _OutputIterator, typename _Size, typename _Tp>
     inline typename
-    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
+    __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, _OutputIterator>::__type
     __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
     {
       for (; __n > 0; --__n, ++__first)
@@ -1371,7 +1371,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
     }
   template<typename _OutputIterator, typename _Size, typename _Tp>
     inline typename
-    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
+    __gnu_cxx::__enable_if<____is_scalar<_Tp>::__value, _OutputIterator>::__type
     __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
     {
       const _Tp __tmp = __value;
diff --git a/gcc/testsuite/g++.dg/torture/pr57107.C b/gcc/testsuite/g++.dg/torture/pr57107.C
index 4dbd32bd298..65fd74ded9a 100644
--- a/gcc/testsuite/g++.dg/torture/pr57107.C
+++ b/gcc/testsuite/g++.dg/torture/pr57107.C
@@ -27,7 +27,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
     };
     template<typename _Tp>     struct __is_arithmetic     : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> >     {
     };
-    template<typename _Tp>     struct __is_scalar     : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >     {
+    template<typename _Tp>     struct ____is_scalar     : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >     {
     };
 }
 namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) {
@@ -54,7 +54,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
     };
     template<typename _Iterator>     inline typename _Niter_base<_Iterator>::iterator_type     __niter_base(_Iterator __it)     {
     }
-    template<typename _OutputIterator, typename _Size, typename _Tp>     inline typename     __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type     __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)     {
+    template<typename _OutputIterator, typename _Size, typename _Tp>     inline typename     __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, _OutputIterator>::__type     __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)     {
 	for (__decltype(__n + 0) __niter = __n;
 	     __niter > 0;
 	     --__niter, ++__first)  *__first = __value;
diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h
index 4312f32a4e0..f7f0d558421 100644
--- a/libstdc++-v3/include/bits/cpp_type_traits.h
+++ b/libstdc++-v3/include/bits/cpp_type_traits.h
@@ -389,7 +389,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
   // A scalar type is an arithmetic type or a pointer type
   // 
   template<typename _Tp>
-    struct __is_scalar
+    struct ____is_scalar
     : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >
     { };
 
diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h
index dd95e94f7e9..f292d26fbf0 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -911,7 +911,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
   template<typename _ForwardIterator, typename _Tp>
     _GLIBCXX20_CONSTEXPR
     inline typename
-    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, void>::__type
+    __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, void>::__type
     __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
 	      const _Tp& __value)
     {
@@ -922,7 +922,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
   template<typename _ForwardIterator, typename _Tp>
     _GLIBCXX20_CONSTEXPR
     inline typename
-    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type
+    __gnu_cxx::__enable_if<____is_scalar<_Tp>::__value, void>::__type
     __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
 	      const _Tp& __value)
     {
@@ -1060,7 +1060,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
   template<typename _OutputIterator, typename _Size, typename _Tp>
     _GLIBCXX20_CONSTEXPR
     inline typename
-    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
+    __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, _OutputIterator>::__type
     __fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value)
     {
       for (; __n > 0; --__n, (void) ++__first)
@@ -1071,7 +1071,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
   template<typename _OutputIterator, typename _Size, typename _Tp>
     _GLIBCXX20_CONSTEXPR
     inline typename
-    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
+    __gnu_cxx::__enable_if<____is_scalar<_Tp>::__value, _OutputIterator>::__type
     __fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value)
     {
       const _Tp __tmp = __value;
diff --git a/libstdc++-v3/include/bits/valarray_array.h b/libstdc++-v3/include/bits/valarray_array.h
index 222fd5fd900..682770ad7db 100644
--- a/libstdc++-v3/include/bits/valarray_array.h
+++ b/libstdc++-v3/include/bits/valarray_array.h
@@ -90,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     inline void
     __valarray_default_construct(_Tp* __b, _Tp* __e)
     {
-      _Array_default_ctor<_Tp, __is_scalar<_Tp>::__value>::_S_do_it(__b, __e);
+      _Array_default_ctor<_Tp, ____is_scalar<_Tp>::__value>::_S_do_it(__b, __e);
     }
 
   // Turn a raw-memory into an array of _Tp filled with __t
-- 
2.41.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 2/2] libstdc++: use new built-in trait __is_scalar for std::is_scalar
  2023-07-03  9:13 [PATCH 1/2] c++, libstdc++: implement __is_scalar built-in trait Ken Matsui
@ 2023-07-03  9:13 ` Ken Matsui
  2023-07-03 10:00 ` [PATCH 1/2] c++, libstdc++: implement __is_scalar built-in trait Ken Matsui
  1 sibling, 0 replies; 12+ messages in thread
From: Ken Matsui @ 2023-07-03  9:13 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++, Ken Matsui

This patch gets std::is_scalar to dispatch to new built-in trait
__is_scalar.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_scalar): Use __is_scalar built-in
	trait.
	(is_scalar_v): Likewise.

Signed-off-by: Ken Matsui <kmatsui@cs.washington.edu>
---
 libstdc++-v3/include/std/type_traits | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 0e7a9c9c7f3..bc90b2c61ca 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -678,11 +678,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct is_member_pointer;
 
   /// is_scalar
+#if __has_builtin(__is_scalar)
+  template<typename _Tp>
+    struct is_scalar
+    : public __bool_constant<__is_scalar(_Tp)>
+    { };
+#else
   template<typename _Tp>
     struct is_scalar
     : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
                    is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
     { };
+#endif
 
   /// is_compound
   template<typename _Tp>
@@ -3204,8 +3211,15 @@ template <typename _Tp>
   inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
 template <typename _Tp>
   inline constexpr bool is_object_v = is_object<_Tp>::value;
+
+#if __has_builtin(__is_scalar)
+template <typename _Tp>
+  inline constexpr bool is_scalar_v = __is_scalar(_Tp);
+#else
 template <typename _Tp>
   inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
+#endif
+
 template <typename _Tp>
   inline constexpr bool is_compound_v = is_compound<_Tp>::value;
 template <typename _Tp>
-- 
2.41.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/2] c++, libstdc++: implement __is_scalar built-in trait
  2023-07-03  9:13 [PATCH 1/2] c++, libstdc++: implement __is_scalar built-in trait Ken Matsui
  2023-07-03  9:13 ` [PATCH 2/2] libstdc++: use new built-in trait __is_scalar for std::is_scalar Ken Matsui
@ 2023-07-03 10:00 ` Ken Matsui
  2023-07-08  4:45   ` [PATCH v2 " Ken Matsui
  1 sibling, 1 reply; 12+ messages in thread
From: Ken Matsui @ 2023-07-03 10:00 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++

Hi,

Here is the benchmark result for is_scalar:

https://github.com/ken-matsui/gcc-benches/blob/main/is_scalar.md#mon-jul--3-022250-am-pdt-2023

Time: -90.6237%
Peak Memory Usage: -78.5155%
Total Memory Usage: -82.1901%

Sincerely,
Ken Matsui

On Mon, Jul 3, 2023 at 2:14 AM Ken Matsui <kmatsui@cs.washington.edu> wrote:
>
> This patch implements built-in trait for std::is_scalar. The existent
> __is_scalar codes were replaced with ____is_scalar to avoid unintentional
> macro replacement by the new built-in.
>
> gcc/cp/ChangeLog:
>
>         * cp-trait.def: Define __is_scalar.
>         * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SCALAR.
>         * semantics.cc (trait_expr_value): Likewise.
>         (finish_trait_expr): Likewise.
>
> gcc/testsuite/ChangeLog:
>
>         * g++.dg/ext/has-builtin-1.C: Test existence of __is_scalar.
>         * g++.dg/ext/is_scalar.C: New test.
>         * g++.dg/tm/pr46567.C: Use ____is_scalar instead.
>         * g++.dg/torture/pr57107.C: Likewise.
>
> libstdc++-v3/ChangeLog:
>
>         * include/bits/cpp_type_traits.h (__is_scalar): Rename to ...
>         (____is_scalar): ... this.
>         * include/bits/stl_algobase.h: Use ____is_scalar instead.
>         * include/bits/valarray_array.h: Likewise.
>
> Signed-off-by: Ken Matsui <kmatsui@cs.washington.edu>
> ---
>  gcc/cp/constraint.cc                        |  3 ++
>  gcc/cp/cp-trait.def                         |  1 +
>  gcc/cp/semantics.cc                         |  4 +++
>  gcc/testsuite/g++.dg/ext/has-builtin-1.C    |  3 ++
>  gcc/testsuite/g++.dg/ext/is_scalar.C        | 31 +++++++++++++++++++++
>  gcc/testsuite/g++.dg/tm/pr46567.C           | 10 +++----
>  gcc/testsuite/g++.dg/torture/pr57107.C      |  4 +--
>  libstdc++-v3/include/bits/cpp_type_traits.h |  2 +-
>  libstdc++-v3/include/bits/stl_algobase.h    |  8 +++---
>  libstdc++-v3/include/bits/valarray_array.h  |  2 +-
>  10 files changed, 55 insertions(+), 13 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/ext/is_scalar.C
>
> diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
> index 8cf0f2d0974..4c27f2a3a62 100644
> --- a/gcc/cp/constraint.cc
> +++ b/gcc/cp/constraint.cc
> @@ -3751,6 +3751,9 @@ diagnose_trait_expr (tree expr, tree args)
>      case CPTK_IS_UNION:
>        inform (loc, "  %qT is not a union", t1);
>        break;
> +    case CPTK_IS_SCALAR:
> +      inform (loc, "  %qT is not a scalar type", t1);
> +      break;
>      case CPTK_IS_AGGREGATE:
>        inform (loc, "  %qT is not an aggregate", t1);
>        break;
> diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
> index 8b7fece0cc8..59ae087c457 100644
> --- a/gcc/cp/cp-trait.def
> +++ b/gcc/cp/cp-trait.def
> @@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2)
>  DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1)
>  DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1)
>  DEFTRAIT_EXPR (IS_UNION, "__is_union", 1)
> +DEFTRAIT_EXPR (IS_SCALAR, "__is_scalar", 1)
>  DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2)
>  DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2)
>  /* FIXME Added space to avoid direct usage in GCC 13.  */
> diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
> index 8fb47fd179e..3edc7f23212 100644
> --- a/gcc/cp/semantics.cc
> +++ b/gcc/cp/semantics.cc
> @@ -12118,6 +12118,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
>      case CPTK_IS_UNION:
>        return type_code1 == UNION_TYPE;
>
> +    case CPTK_IS_SCALAR:
> +      return SCALAR_TYPE_P (type1);
> +
>      case CPTK_IS_ASSIGNABLE:
>        return is_xible (MODIFY_EXPR, type1, type2);
>
> @@ -12296,6 +12299,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2)
>      case CPTK_IS_ENUM:
>      case CPTK_IS_UNION:
>      case CPTK_IS_SAME:
> +    case CPTK_IS_SCALAR:
>        break;
>
>      case CPTK_IS_LAYOUT_COMPATIBLE:
> diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> index f343e153e56..75acbdfb9fc 100644
> --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> @@ -146,3 +146,6 @@
>  #if !__has_builtin (__remove_cvref)
>  # error "__has_builtin (__remove_cvref) failed"
>  #endif
> +#if !__has_builtin (__is_scalar)
> +# error "__has_builtin (__is_scalar) failed"
> +#endif
> diff --git a/gcc/testsuite/g++.dg/ext/is_scalar.C b/gcc/testsuite/g++.dg/ext/is_scalar.C
> new file mode 100644
> index 00000000000..457fddc52fc
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/ext/is_scalar.C
> @@ -0,0 +1,31 @@
> +// { dg-do compile { target c++11 } }
> +
> +#include <cstddef>  // std::nullptr_t
> +#include <testsuite_tr1.h>
> +
> +using namespace __gnu_test;
> +
> +#define SA(X) static_assert((X),#X)
> +
> +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT)  \
> +  SA(TRAIT(TYPE) == EXPECT);                                   \
> +  SA(TRAIT(const TYPE) == EXPECT);                             \
> +  SA(TRAIT(volatile TYPE) == EXPECT);                  \
> +  SA(TRAIT(const volatile TYPE) == EXPECT)
> +
> +// volatile return type would cause a warning.
> +#define SA_FN_TEST_CATEGORY(TRAIT, TYPE, EXPECT)       \
> +  SA(TRAIT(TYPE) == EXPECT);                                           \
> +  SA(TRAIT(const TYPE) == EXPECT)
> +
> +SA_TEST_CATEGORY(__is_scalar, int, true);
> +SA_TEST_CATEGORY(__is_scalar, float, true);
> +SA_TEST_CATEGORY(__is_scalar, EnumType, true);
> +SA_TEST_CATEGORY(__is_scalar, int*, true);
> +SA_FN_TEST_CATEGORY(__is_scalar, int(*)(int), true);
> +SA_TEST_CATEGORY(__is_scalar, int (ClassType::*), true);
> +SA_FN_TEST_CATEGORY(__is_scalar, int (ClassType::*) (int), true);
> +SA_TEST_CATEGORY(__is_scalar, std::nullptr_t, true);
> +
> +// Sanity check.
> +SA_TEST_CATEGORY(__is_scalar, ClassType, false);
> diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C
> index 6d791484448..d79e0afb462 100644
> --- a/gcc/testsuite/g++.dg/tm/pr46567.C
> +++ b/gcc/testsuite/g++.dg/tm/pr46567.C
> @@ -225,7 +225,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
>      : public __traitor<__is_void<_Tp>, __is_arithmetic<_Tp> >
>      { };
>    template<typename _Tp>
> -    struct __is_scalar
> +    struct ____is_scalar
>      : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >
>      { };
>    template<typename _Tp>
> @@ -1325,7 +1325,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
>      }
>    template<typename _ForwardIterator, typename _Tp>
>      inline typename
> -    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, void>::__type
> +    __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, void>::__type
>      __fill_a(_ForwardIterator __first, _ForwardIterator __last,
>         const _Tp& __value)
>      {
> @@ -1334,7 +1334,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
>      }
>    template<typename _ForwardIterator, typename _Tp>
>      inline typename
> -    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type
> +    __gnu_cxx::__enable_if<____is_scalar<_Tp>::__value, void>::__type
>      __fill_a(_ForwardIterator __first, _ForwardIterator __last,
>        const _Tp& __value)
>      {
> @@ -1362,7 +1362,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
>      }
>    template<typename _OutputIterator, typename _Size, typename _Tp>
>      inline typename
> -    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
> +    __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, _OutputIterator>::__type
>      __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
>      {
>        for (; __n > 0; --__n, ++__first)
> @@ -1371,7 +1371,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
>      }
>    template<typename _OutputIterator, typename _Size, typename _Tp>
>      inline typename
> -    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
> +    __gnu_cxx::__enable_if<____is_scalar<_Tp>::__value, _OutputIterator>::__type
>      __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
>      {
>        const _Tp __tmp = __value;
> diff --git a/gcc/testsuite/g++.dg/torture/pr57107.C b/gcc/testsuite/g++.dg/torture/pr57107.C
> index 4dbd32bd298..65fd74ded9a 100644
> --- a/gcc/testsuite/g++.dg/torture/pr57107.C
> +++ b/gcc/testsuite/g++.dg/torture/pr57107.C
> @@ -27,7 +27,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
>      };
>      template<typename _Tp>     struct __is_arithmetic     : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> >     {
>      };
> -    template<typename _Tp>     struct __is_scalar     : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >     {
> +    template<typename _Tp>     struct ____is_scalar     : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >     {
>      };
>  }
>  namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) {
> @@ -54,7 +54,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
>      };
>      template<typename _Iterator>     inline typename _Niter_base<_Iterator>::iterator_type     __niter_base(_Iterator __it)     {
>      }
> -    template<typename _OutputIterator, typename _Size, typename _Tp>     inline typename     __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type     __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)     {
> +    template<typename _OutputIterator, typename _Size, typename _Tp>     inline typename     __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, _OutputIterator>::__type     __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)     {
>         for (__decltype(__n + 0) __niter = __n;
>              __niter > 0;
>              --__niter, ++__first)  *__first = __value;
> diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h
> index 4312f32a4e0..f7f0d558421 100644
> --- a/libstdc++-v3/include/bits/cpp_type_traits.h
> +++ b/libstdc++-v3/include/bits/cpp_type_traits.h
> @@ -389,7 +389,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
>    // A scalar type is an arithmetic type or a pointer type
>    //
>    template<typename _Tp>
> -    struct __is_scalar
> +    struct ____is_scalar
>      : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >
>      { };
>
> diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h
> index dd95e94f7e9..f292d26fbf0 100644
> --- a/libstdc++-v3/include/bits/stl_algobase.h
> +++ b/libstdc++-v3/include/bits/stl_algobase.h
> @@ -911,7 +911,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
>    template<typename _ForwardIterator, typename _Tp>
>      _GLIBCXX20_CONSTEXPR
>      inline typename
> -    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, void>::__type
> +    __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, void>::__type
>      __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
>               const _Tp& __value)
>      {
> @@ -922,7 +922,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
>    template<typename _ForwardIterator, typename _Tp>
>      _GLIBCXX20_CONSTEXPR
>      inline typename
> -    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type
> +    __gnu_cxx::__enable_if<____is_scalar<_Tp>::__value, void>::__type
>      __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
>               const _Tp& __value)
>      {
> @@ -1060,7 +1060,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
>    template<typename _OutputIterator, typename _Size, typename _Tp>
>      _GLIBCXX20_CONSTEXPR
>      inline typename
> -    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
> +    __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, _OutputIterator>::__type
>      __fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value)
>      {
>        for (; __n > 0; --__n, (void) ++__first)
> @@ -1071,7 +1071,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
>    template<typename _OutputIterator, typename _Size, typename _Tp>
>      _GLIBCXX20_CONSTEXPR
>      inline typename
> -    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
> +    __gnu_cxx::__enable_if<____is_scalar<_Tp>::__value, _OutputIterator>::__type
>      __fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value)
>      {
>        const _Tp __tmp = __value;
> diff --git a/libstdc++-v3/include/bits/valarray_array.h b/libstdc++-v3/include/bits/valarray_array.h
> index 222fd5fd900..682770ad7db 100644
> --- a/libstdc++-v3/include/bits/valarray_array.h
> +++ b/libstdc++-v3/include/bits/valarray_array.h
> @@ -90,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>      inline void
>      __valarray_default_construct(_Tp* __b, _Tp* __e)
>      {
> -      _Array_default_ctor<_Tp, __is_scalar<_Tp>::__value>::_S_do_it(__b, __e);
> +      _Array_default_ctor<_Tp, ____is_scalar<_Tp>::__value>::_S_do_it(__b, __e);
>      }
>
>    // Turn a raw-memory into an array of _Tp filled with __t
> --
> 2.41.0
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 1/2] c++, libstdc++: implement __is_scalar built-in trait
  2023-07-03 10:00 ` [PATCH 1/2] c++, libstdc++: implement __is_scalar built-in trait Ken Matsui
@ 2023-07-08  4:45   ` Ken Matsui
  2023-07-08  4:45     ` [PATCH v2 2/2] libstdc++: use new built-in trait __is_scalar for std::is_scalar Ken Matsui
  2023-09-04 15:00     ` [PING][PATCH v2 1/2] c++, libstdc++: implement __is_scalar built-in trait Ken Matsui
  0 siblings, 2 replies; 12+ messages in thread
From: Ken Matsui @ 2023-07-08  4:45 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++, Ken Matsui

This patch implements built-in trait for std::is_scalar. The existent
__is_scalar codes were replaced with ____is_scalar to avoid unintentional
macro replacement by the new built-in.

gcc/cp/ChangeLog:

	* cp-trait.def: Define __is_scalar.
	* constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SCALAR.
	* semantics.cc (trait_expr_value): Likewise.
	(finish_trait_expr): Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/ext/has-builtin-1.C: Test existence of __is_scalar.
	* g++.dg/ext/is_scalar.C: New test.
	* g++.dg/tm/pr46567.C: Use ____is_scalar instead.
	* g++.dg/torture/pr57107.C: Likewise.

libstdc++-v3/ChangeLog:

	* include/bits/cpp_type_traits.h (__is_scalar): Rename to ...
	(____is_scalar): ... this.
	* include/bits/stl_algobase.h: Use ____is_scalar instead.
	* include/bits/valarray_array.h: Likewise.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
---
 gcc/cp/constraint.cc                        |  3 ++
 gcc/cp/cp-trait.def                         |  1 +
 gcc/cp/semantics.cc                         |  4 +++
 gcc/testsuite/g++.dg/ext/has-builtin-1.C    |  3 ++
 gcc/testsuite/g++.dg/ext/is_scalar.C        | 31 +++++++++++++++++++++
 gcc/testsuite/g++.dg/tm/pr46567.C           | 10 +++----
 gcc/testsuite/g++.dg/torture/pr57107.C      |  4 +--
 libstdc++-v3/include/bits/cpp_type_traits.h |  2 +-
 libstdc++-v3/include/bits/stl_algobase.h    |  8 +++---
 libstdc++-v3/include/bits/valarray_array.h  |  2 +-
 10 files changed, 55 insertions(+), 13 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/is_scalar.C

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 8cf0f2d0974..4c27f2a3a62 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3751,6 +3751,9 @@ diagnose_trait_expr (tree expr, tree args)
     case CPTK_IS_UNION:
       inform (loc, "  %qT is not a union", t1);
       break;
+    case CPTK_IS_SCALAR:
+      inform (loc, "  %qT is not a scalar type", t1);
+      break;
     case CPTK_IS_AGGREGATE:
       inform (loc, "  %qT is not an aggregate", t1);
       break;
diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
index 8b7fece0cc8..59ae087c457 100644
--- a/gcc/cp/cp-trait.def
+++ b/gcc/cp/cp-trait.def
@@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2)
 DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1)
 DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1)
 DEFTRAIT_EXPR (IS_UNION, "__is_union", 1)
+DEFTRAIT_EXPR (IS_SCALAR, "__is_scalar", 1)
 DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2)
 DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2)
 /* FIXME Added space to avoid direct usage in GCC 13.  */
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 8fb47fd179e..3edc7f23212 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12118,6 +12118,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
     case CPTK_IS_UNION:
       return type_code1 == UNION_TYPE;
 
+    case CPTK_IS_SCALAR:
+      return SCALAR_TYPE_P (type1);
+
     case CPTK_IS_ASSIGNABLE:
       return is_xible (MODIFY_EXPR, type1, type2);
 
@@ -12296,6 +12299,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2)
     case CPTK_IS_ENUM:
     case CPTK_IS_UNION:
     case CPTK_IS_SAME:
+    case CPTK_IS_SCALAR:
       break;
 
     case CPTK_IS_LAYOUT_COMPATIBLE:
diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
index f343e153e56..75acbdfb9fc 100644
--- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
+++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
@@ -146,3 +146,6 @@
 #if !__has_builtin (__remove_cvref)
 # error "__has_builtin (__remove_cvref) failed"
 #endif
+#if !__has_builtin (__is_scalar)
+# error "__has_builtin (__is_scalar) failed"
+#endif
diff --git a/gcc/testsuite/g++.dg/ext/is_scalar.C b/gcc/testsuite/g++.dg/ext/is_scalar.C
new file mode 100644
index 00000000000..457fddc52fc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_scalar.C
@@ -0,0 +1,31 @@
+// { dg-do compile { target c++11 } }
+
+#include <cstddef>  // std::nullptr_t
+#include <testsuite_tr1.h>
+
+using namespace __gnu_test;
+
+#define SA(X) static_assert((X),#X)
+
+#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT)	\
+  SA(TRAIT(TYPE) == EXPECT);					\
+  SA(TRAIT(const TYPE) == EXPECT);				\
+  SA(TRAIT(volatile TYPE) == EXPECT);			\
+  SA(TRAIT(const volatile TYPE) == EXPECT)
+
+// volatile return type would cause a warning.
+#define SA_FN_TEST_CATEGORY(TRAIT, TYPE, EXPECT)	\
+  SA(TRAIT(TYPE) == EXPECT);						\
+  SA(TRAIT(const TYPE) == EXPECT)
+
+SA_TEST_CATEGORY(__is_scalar, int, true);
+SA_TEST_CATEGORY(__is_scalar, float, true);
+SA_TEST_CATEGORY(__is_scalar, EnumType, true);
+SA_TEST_CATEGORY(__is_scalar, int*, true);
+SA_FN_TEST_CATEGORY(__is_scalar, int(*)(int), true);
+SA_TEST_CATEGORY(__is_scalar, int (ClassType::*), true);
+SA_FN_TEST_CATEGORY(__is_scalar, int (ClassType::*) (int), true);
+SA_TEST_CATEGORY(__is_scalar, std::nullptr_t, true);
+
+// Sanity check.
+SA_TEST_CATEGORY(__is_scalar, ClassType, false);
diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C
index 6d791484448..d79e0afb462 100644
--- a/gcc/testsuite/g++.dg/tm/pr46567.C
+++ b/gcc/testsuite/g++.dg/tm/pr46567.C
@@ -225,7 +225,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
     : public __traitor<__is_void<_Tp>, __is_arithmetic<_Tp> >
     { };
   template<typename _Tp>
-    struct __is_scalar
+    struct ____is_scalar
     : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >
     { };
   template<typename _Tp>
@@ -1325,7 +1325,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
     }
   template<typename _ForwardIterator, typename _Tp>
     inline typename
-    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, void>::__type
+    __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, void>::__type
     __fill_a(_ForwardIterator __first, _ForwardIterator __last,
        const _Tp& __value)
     {
@@ -1334,7 +1334,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
     }
   template<typename _ForwardIterator, typename _Tp>
     inline typename
-    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type
+    __gnu_cxx::__enable_if<____is_scalar<_Tp>::__value, void>::__type
     __fill_a(_ForwardIterator __first, _ForwardIterator __last,
       const _Tp& __value)
     {
@@ -1362,7 +1362,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
     }
   template<typename _OutputIterator, typename _Size, typename _Tp>
     inline typename
-    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
+    __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, _OutputIterator>::__type
     __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
     {
       for (; __n > 0; --__n, ++__first)
@@ -1371,7 +1371,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
     }
   template<typename _OutputIterator, typename _Size, typename _Tp>
     inline typename
-    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
+    __gnu_cxx::__enable_if<____is_scalar<_Tp>::__value, _OutputIterator>::__type
     __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
     {
       const _Tp __tmp = __value;
diff --git a/gcc/testsuite/g++.dg/torture/pr57107.C b/gcc/testsuite/g++.dg/torture/pr57107.C
index 4dbd32bd298..65fd74ded9a 100644
--- a/gcc/testsuite/g++.dg/torture/pr57107.C
+++ b/gcc/testsuite/g++.dg/torture/pr57107.C
@@ -27,7 +27,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
     };
     template<typename _Tp>     struct __is_arithmetic     : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> >     {
     };
-    template<typename _Tp>     struct __is_scalar     : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >     {
+    template<typename _Tp>     struct ____is_scalar     : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >     {
     };
 }
 namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) {
@@ -54,7 +54,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
     };
     template<typename _Iterator>     inline typename _Niter_base<_Iterator>::iterator_type     __niter_base(_Iterator __it)     {
     }
-    template<typename _OutputIterator, typename _Size, typename _Tp>     inline typename     __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type     __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)     {
+    template<typename _OutputIterator, typename _Size, typename _Tp>     inline typename     __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, _OutputIterator>::__type     __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)     {
 	for (__decltype(__n + 0) __niter = __n;
 	     __niter > 0;
 	     --__niter, ++__first)  *__first = __value;
diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h
index 4312f32a4e0..f7f0d558421 100644
--- a/libstdc++-v3/include/bits/cpp_type_traits.h
+++ b/libstdc++-v3/include/bits/cpp_type_traits.h
@@ -389,7 +389,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
   // A scalar type is an arithmetic type or a pointer type
   // 
   template<typename _Tp>
-    struct __is_scalar
+    struct ____is_scalar
     : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >
     { };
 
diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h
index dd95e94f7e9..f292d26fbf0 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -911,7 +911,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
   template<typename _ForwardIterator, typename _Tp>
     _GLIBCXX20_CONSTEXPR
     inline typename
-    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, void>::__type
+    __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, void>::__type
     __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
 	      const _Tp& __value)
     {
@@ -922,7 +922,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
   template<typename _ForwardIterator, typename _Tp>
     _GLIBCXX20_CONSTEXPR
     inline typename
-    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type
+    __gnu_cxx::__enable_if<____is_scalar<_Tp>::__value, void>::__type
     __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
 	      const _Tp& __value)
     {
@@ -1060,7 +1060,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
   template<typename _OutputIterator, typename _Size, typename _Tp>
     _GLIBCXX20_CONSTEXPR
     inline typename
-    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
+    __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, _OutputIterator>::__type
     __fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value)
     {
       for (; __n > 0; --__n, (void) ++__first)
@@ -1071,7 +1071,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
   template<typename _OutputIterator, typename _Size, typename _Tp>
     _GLIBCXX20_CONSTEXPR
     inline typename
-    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
+    __gnu_cxx::__enable_if<____is_scalar<_Tp>::__value, _OutputIterator>::__type
     __fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value)
     {
       const _Tp __tmp = __value;
diff --git a/libstdc++-v3/include/bits/valarray_array.h b/libstdc++-v3/include/bits/valarray_array.h
index 222fd5fd900..682770ad7db 100644
--- a/libstdc++-v3/include/bits/valarray_array.h
+++ b/libstdc++-v3/include/bits/valarray_array.h
@@ -90,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     inline void
     __valarray_default_construct(_Tp* __b, _Tp* __e)
     {
-      _Array_default_ctor<_Tp, __is_scalar<_Tp>::__value>::_S_do_it(__b, __e);
+      _Array_default_ctor<_Tp, ____is_scalar<_Tp>::__value>::_S_do_it(__b, __e);
     }
 
   // Turn a raw-memory into an array of _Tp filled with __t
-- 
2.41.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 2/2] libstdc++: use new built-in trait __is_scalar for std::is_scalar
  2023-07-08  4:45   ` [PATCH v2 " Ken Matsui
@ 2023-07-08  4:45     ` Ken Matsui
  2023-07-12  9:50       ` Jonathan Wakely
  2023-09-04 15:00     ` [PING][PATCH v2 1/2] c++, libstdc++: implement __is_scalar built-in trait Ken Matsui
  1 sibling, 1 reply; 12+ messages in thread
From: Ken Matsui @ 2023-07-08  4:45 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++, Ken Matsui

This patch gets std::is_scalar to dispatch to new built-in trait
__is_scalar.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_scalar): Use __is_scalar built-in
	trait.
	(is_scalar_v): Likewise.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
---
 libstdc++-v3/include/std/type_traits | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 0e7a9c9c7f3..bc90b2c61ca 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -678,11 +678,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct is_member_pointer;
 
   /// is_scalar
+#if __has_builtin(__is_scalar)
+  template<typename _Tp>
+    struct is_scalar
+    : public __bool_constant<__is_scalar(_Tp)>
+    { };
+#else
   template<typename _Tp>
     struct is_scalar
     : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
                    is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
     { };
+#endif
 
   /// is_compound
   template<typename _Tp>
@@ -3204,8 +3211,15 @@ template <typename _Tp>
   inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
 template <typename _Tp>
   inline constexpr bool is_object_v = is_object<_Tp>::value;
+
+#if __has_builtin(__is_scalar)
+template <typename _Tp>
+  inline constexpr bool is_scalar_v = __is_scalar(_Tp);
+#else
 template <typename _Tp>
   inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
+#endif
+
 template <typename _Tp>
   inline constexpr bool is_compound_v = is_compound<_Tp>::value;
 template <typename _Tp>
-- 
2.41.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/2] libstdc++: use new built-in trait __is_scalar for std::is_scalar
  2023-07-08  4:45     ` [PATCH v2 2/2] libstdc++: use new built-in trait __is_scalar for std::is_scalar Ken Matsui
@ 2023-07-12  9:50       ` Jonathan Wakely
  2023-07-12 18:32         ` Ken Matsui
  0 siblings, 1 reply; 12+ messages in thread
From: Jonathan Wakely @ 2023-07-12  9:50 UTC (permalink / raw)
  To: Ken Matsui; +Cc: gcc-patches, libstdc++

On Sat, 8 Jul 2023 at 05:47, Ken Matsui via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> This patch gets std::is_scalar to dispatch to new built-in trait
> __is_scalar.
>
> libstdc++-v3/ChangeLog:
>
>         * include/std/type_traits (is_scalar): Use __is_scalar built-in
>         trait.
>         (is_scalar_v): Likewise.

OK for trunk (conditional on the front-end change being committed
first of course).


>
> Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
> ---
>  libstdc++-v3/include/std/type_traits | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
> index 0e7a9c9c7f3..bc90b2c61ca 100644
> --- a/libstdc++-v3/include/std/type_traits
> +++ b/libstdc++-v3/include/std/type_traits
> @@ -678,11 +678,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>      struct is_member_pointer;
>
>    /// is_scalar
> +#if __has_builtin(__is_scalar)
> +  template<typename _Tp>
> +    struct is_scalar
> +    : public __bool_constant<__is_scalar(_Tp)>
> +    { };
> +#else
>    template<typename _Tp>
>      struct is_scalar
>      : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
>                     is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
>      { };
> +#endif
>
>    /// is_compound
>    template<typename _Tp>
> @@ -3204,8 +3211,15 @@ template <typename _Tp>
>    inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
>  template <typename _Tp>
>    inline constexpr bool is_object_v = is_object<_Tp>::value;
> +
> +#if __has_builtin(__is_scalar)
> +template <typename _Tp>
> +  inline constexpr bool is_scalar_v = __is_scalar(_Tp);
> +#else
>  template <typename _Tp>
>    inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
> +#endif
> +
>  template <typename _Tp>
>    inline constexpr bool is_compound_v = is_compound<_Tp>::value;
>  template <typename _Tp>
> --
> 2.41.0
>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/2] libstdc++: use new built-in trait __is_scalar for std::is_scalar
  2023-07-12  9:50       ` Jonathan Wakely
@ 2023-07-12 18:32         ` Ken Matsui
  2023-07-12 18:56           ` Xi Ruoyao
  2023-07-12 19:23           ` Jonathan Wakely
  0 siblings, 2 replies; 12+ messages in thread
From: Ken Matsui @ 2023-07-12 18:32 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: Ken Matsui, gcc-patches, libstdc++

On Wed, Jul 12, 2023 at 2:50 AM Jonathan Wakely <jwakely@redhat.com> wrote:
>
> On Sat, 8 Jul 2023 at 05:47, Ken Matsui via Libstdc++
> <libstdc++@gcc.gnu.org> wrote:
> >
> > This patch gets std::is_scalar to dispatch to new built-in trait
> > __is_scalar.
> >
> > libstdc++-v3/ChangeLog:
> >
> >         * include/std/type_traits (is_scalar): Use __is_scalar built-in
> >         trait.
> >         (is_scalar_v): Likewise.
>
> OK for trunk (conditional on the front-end change being committed
> first of course).
>

Thank you for your review!

Just to confirm, this approval does not include the [1/2] patch, does
it? Or, did you approve this entire patch series?

> conditional on the front-end change being committed first of course

Does this mean we want to commit this [2/2] patch before committing
the [1/2] patch in this case?

Also, can I tweak the commit message without being approved again,
such as attaching the benchmark result?

> >
> > Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
> > ---
> >  libstdc++-v3/include/std/type_traits | 14 ++++++++++++++
> >  1 file changed, 14 insertions(+)
> >
> > diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
> > index 0e7a9c9c7f3..bc90b2c61ca 100644
> > --- a/libstdc++-v3/include/std/type_traits
> > +++ b/libstdc++-v3/include/std/type_traits
> > @@ -678,11 +678,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >      struct is_member_pointer;
> >
> >    /// is_scalar
> > +#if __has_builtin(__is_scalar)
> > +  template<typename _Tp>
> > +    struct is_scalar
> > +    : public __bool_constant<__is_scalar(_Tp)>
> > +    { };
> > +#else
> >    template<typename _Tp>
> >      struct is_scalar
> >      : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
> >                     is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
> >      { };
> > +#endif
> >
> >    /// is_compound
> >    template<typename _Tp>
> > @@ -3204,8 +3211,15 @@ template <typename _Tp>
> >    inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
> >  template <typename _Tp>
> >    inline constexpr bool is_object_v = is_object<_Tp>::value;
> > +
> > +#if __has_builtin(__is_scalar)
> > +template <typename _Tp>
> > +  inline constexpr bool is_scalar_v = __is_scalar(_Tp);
> > +#else
> >  template <typename _Tp>
> >    inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
> > +#endif
> > +
> >  template <typename _Tp>
> >    inline constexpr bool is_compound_v = is_compound<_Tp>::value;
> >  template <typename _Tp>
> > --
> > 2.41.0
> >
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/2] libstdc++: use new built-in trait __is_scalar for std::is_scalar
  2023-07-12 18:32         ` Ken Matsui
@ 2023-07-12 18:56           ` Xi Ruoyao
  2023-07-12 19:06             ` Ken Matsui
  2023-07-12 19:23           ` Jonathan Wakely
  1 sibling, 1 reply; 12+ messages in thread
From: Xi Ruoyao @ 2023-07-12 18:56 UTC (permalink / raw)
  To: Ken Matsui, Jonathan Wakely; +Cc: Ken Matsui, gcc-patches, libstdc++

On Wed, 2023-07-12 at 11:32 -0700, Ken Matsui via Gcc-patches wrote:
> > conditional on the front-end change being committed first of course
> 
> Does this mean we want to commit this [2/2] patch before committing
> the [1/2] patch in this case?

No, this mean you should get 1/2 reviewed and committed first.

> Also, can I tweak the commit message without being approved again,
> such as attaching the benchmark result?

Yes, as long as the ChangeLog is still correct (the Git hook will reject
a push with wrong ChangeLog format anyway).

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/2] libstdc++: use new built-in trait __is_scalar for std::is_scalar
  2023-07-12 18:56           ` Xi Ruoyao
@ 2023-07-12 19:06             ` Ken Matsui
  0 siblings, 0 replies; 12+ messages in thread
From: Ken Matsui @ 2023-07-12 19:06 UTC (permalink / raw)
  To: Xi Ruoyao; +Cc: Jonathan Wakely, Ken Matsui, gcc-patches, libstdc++

On Wed, Jul 12, 2023 at 11:56 AM Xi Ruoyao <xry111@xry111.site> wrote:
>
> On Wed, 2023-07-12 at 11:32 -0700, Ken Matsui via Gcc-patches wrote:
> > > conditional on the front-end change being committed first of course
> >
> > Does this mean we want to commit this [2/2] patch before committing
> > the [1/2] patch in this case?
>
> No, this mean you should get 1/2 reviewed and committed first.
>
> > Also, can I tweak the commit message without being approved again,
> > such as attaching the benchmark result?
>
> Yes, as long as the ChangeLog is still correct (the Git hook will reject
> a push with wrong ChangeLog format anyway).

I see. Thank you so much!

> --
> Xi Ruoyao <xry111@xry111.site>
> School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/2] libstdc++: use new built-in trait __is_scalar for std::is_scalar
  2023-07-12 18:32         ` Ken Matsui
  2023-07-12 18:56           ` Xi Ruoyao
@ 2023-07-12 19:23           ` Jonathan Wakely
  2023-07-12 19:35             ` Ken Matsui
  1 sibling, 1 reply; 12+ messages in thread
From: Jonathan Wakely @ 2023-07-12 19:23 UTC (permalink / raw)
  To: Ken Matsui; +Cc: Jonathan Wakely, Ken Matsui, gcc-patches, libstdc++

[-- Attachment #1: Type: text/plain, Size: 3055 bytes --]

On Wed, 12 Jul 2023, 19:33 Ken Matsui via Libstdc++, <libstdc++@gcc.gnu.org>
wrote:

> On Wed, Jul 12, 2023 at 2:50 AM Jonathan Wakely <jwakely@redhat.com>
> wrote:
> >
> > On Sat, 8 Jul 2023 at 05:47, Ken Matsui via Libstdc++
> > <libstdc++@gcc.gnu.org> wrote:
> > >
> > > This patch gets std::is_scalar to dispatch to new built-in trait
> > > __is_scalar.
> > >
> > > libstdc++-v3/ChangeLog:
> > >
> > >         * include/std/type_traits (is_scalar): Use __is_scalar built-in
> > >         trait.
> > >         (is_scalar_v): Likewise.
> >
> > OK for trunk (conditional on the front-end change being committed
> > first of course).
> >
>
> Thank you for your review!
>
> Just to confirm, this approval does not include the [1/2] patch, does
> it? Or, did you approve this entire patch series?
>

Only this patch. I cannot approve compiler changes, I'm only a reviewer for
libstdc++.



> > conditional on the front-end change being committed first of course
>
> Does this mean we want to commit this [2/2] patch before committing
> the [1/2] patch in this case?
>

The other way around, as Xi Ruoyao said.



> Also, can I tweak the commit message without being approved again,
> such as attaching the benchmark result?
>

Yes, that's fine.


> > >
> > > Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
> > > ---
> > >  libstdc++-v3/include/std/type_traits | 14 ++++++++++++++
> > >  1 file changed, 14 insertions(+)
> > >
> > > diff --git a/libstdc++-v3/include/std/type_traits
> b/libstdc++-v3/include/std/type_traits
> > > index 0e7a9c9c7f3..bc90b2c61ca 100644
> > > --- a/libstdc++-v3/include/std/type_traits
> > > +++ b/libstdc++-v3/include/std/type_traits
> > > @@ -678,11 +678,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> > >      struct is_member_pointer;
> > >
> > >    /// is_scalar
> > > +#if __has_builtin(__is_scalar)
> > > +  template<typename _Tp>
> > > +    struct is_scalar
> > > +    : public __bool_constant<__is_scalar(_Tp)>
> > > +    { };
> > > +#else
> > >    template<typename _Tp>
> > >      struct is_scalar
> > >      : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
> > >                     is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
> > >      { };
> > > +#endif
> > >
> > >    /// is_compound
> > >    template<typename _Tp>
> > > @@ -3204,8 +3211,15 @@ template <typename _Tp>
> > >    inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
> > >  template <typename _Tp>
> > >    inline constexpr bool is_object_v = is_object<_Tp>::value;
> > > +
> > > +#if __has_builtin(__is_scalar)
> > > +template <typename _Tp>
> > > +  inline constexpr bool is_scalar_v = __is_scalar(_Tp);
> > > +#else
> > >  template <typename _Tp>
> > >    inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
> > > +#endif
> > > +
> > >  template <typename _Tp>
> > >    inline constexpr bool is_compound_v = is_compound<_Tp>::value;
> > >  template <typename _Tp>
> > > --
> > > 2.41.0
> > >
> >
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/2] libstdc++: use new built-in trait __is_scalar for std::is_scalar
  2023-07-12 19:23           ` Jonathan Wakely
@ 2023-07-12 19:35             ` Ken Matsui
  0 siblings, 0 replies; 12+ messages in thread
From: Ken Matsui @ 2023-07-12 19:35 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: Jonathan Wakely, Ken Matsui, gcc-patches, libstdc++

On Wed, Jul 12, 2023 at 12:23 PM Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>
>
>
> On Wed, 12 Jul 2023, 19:33 Ken Matsui via Libstdc++, <libstdc++@gcc.gnu.org> wrote:
>>
>> On Wed, Jul 12, 2023 at 2:50 AM Jonathan Wakely <jwakely@redhat.com> wrote:
>> >
>> > On Sat, 8 Jul 2023 at 05:47, Ken Matsui via Libstdc++
>> > <libstdc++@gcc.gnu.org> wrote:
>> > >
>> > > This patch gets std::is_scalar to dispatch to new built-in trait
>> > > __is_scalar.
>> > >
>> > > libstdc++-v3/ChangeLog:
>> > >
>> > >         * include/std/type_traits (is_scalar): Use __is_scalar built-in
>> > >         trait.
>> > >         (is_scalar_v): Likewise.
>> >
>> > OK for trunk (conditional on the front-end change being committed
>> > first of course).
>> >
>>
>> Thank you for your review!
>>
>> Just to confirm, this approval does not include the [1/2] patch, does
>> it? Or, did you approve this entire patch series?
>
>
> Only this patch. I cannot approve compiler changes, I'm only a reviewer for libstdc++.
>
>
>>
>> > conditional on the front-end change being committed first of course
>>
>> Does this mean we want to commit this [2/2] patch before committing
>> the [1/2] patch in this case?
>
>
> The other way around, as Xi Ruoyao said.
>
>
>>
>> Also, can I tweak the commit message without being approved again,
>> such as attaching the benchmark result?
>
>
> Yes, that's fine.

Thank you!

>>
>> > >
>> > > Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
>> > > ---
>> > >  libstdc++-v3/include/std/type_traits | 14 ++++++++++++++
>> > >  1 file changed, 14 insertions(+)
>> > >
>> > > diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
>> > > index 0e7a9c9c7f3..bc90b2c61ca 100644
>> > > --- a/libstdc++-v3/include/std/type_traits
>> > > +++ b/libstdc++-v3/include/std/type_traits
>> > > @@ -678,11 +678,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>> > >      struct is_member_pointer;
>> > >
>> > >    /// is_scalar
>> > > +#if __has_builtin(__is_scalar)
>> > > +  template<typename _Tp>
>> > > +    struct is_scalar
>> > > +    : public __bool_constant<__is_scalar(_Tp)>
>> > > +    { };
>> > > +#else
>> > >    template<typename _Tp>
>> > >      struct is_scalar
>> > >      : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
>> > >                     is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
>> > >      { };
>> > > +#endif
>> > >
>> > >    /// is_compound
>> > >    template<typename _Tp>
>> > > @@ -3204,8 +3211,15 @@ template <typename _Tp>
>> > >    inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
>> > >  template <typename _Tp>
>> > >    inline constexpr bool is_object_v = is_object<_Tp>::value;
>> > > +
>> > > +#if __has_builtin(__is_scalar)
>> > > +template <typename _Tp>
>> > > +  inline constexpr bool is_scalar_v = __is_scalar(_Tp);
>> > > +#else
>> > >  template <typename _Tp>
>> > >    inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
>> > > +#endif
>> > > +
>> > >  template <typename _Tp>
>> > >    inline constexpr bool is_compound_v = is_compound<_Tp>::value;
>> > >  template <typename _Tp>
>> > > --
>> > > 2.41.0
>> > >
>> >

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PING][PATCH v2 1/2] c++, libstdc++: implement __is_scalar built-in trait
  2023-07-08  4:45   ` [PATCH v2 " Ken Matsui
  2023-07-08  4:45     ` [PATCH v2 2/2] libstdc++: use new built-in trait __is_scalar for std::is_scalar Ken Matsui
@ 2023-09-04 15:00     ` Ken Matsui
  1 sibling, 0 replies; 12+ messages in thread
From: Ken Matsui @ 2023-09-04 15:00 UTC (permalink / raw)
  To: jason; +Cc: gcc-patches, libstdc++, Ken Matsui

Ping for __is_scalar built-in.

Sincerely,
Ken Matsui

On Fri, Jul 7, 2023 at 9:46 PM Ken Matsui <kmatsui@gcc.gnu.org> wrote:
>
> This patch implements built-in trait for std::is_scalar. The existent
> __is_scalar codes were replaced with ____is_scalar to avoid unintentional
> macro replacement by the new built-in.
>
> gcc/cp/ChangeLog:
>
>         * cp-trait.def: Define __is_scalar.
>         * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SCALAR.
>         * semantics.cc (trait_expr_value): Likewise.
>         (finish_trait_expr): Likewise.
>
> gcc/testsuite/ChangeLog:
>
>         * g++.dg/ext/has-builtin-1.C: Test existence of __is_scalar.
>         * g++.dg/ext/is_scalar.C: New test.
>         * g++.dg/tm/pr46567.C: Use ____is_scalar instead.
>         * g++.dg/torture/pr57107.C: Likewise.
>
> libstdc++-v3/ChangeLog:
>
>         * include/bits/cpp_type_traits.h (__is_scalar): Rename to ...
>         (____is_scalar): ... this.
>         * include/bits/stl_algobase.h: Use ____is_scalar instead.
>         * include/bits/valarray_array.h: Likewise.
>
> Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
> ---
>  gcc/cp/constraint.cc                        |  3 ++
>  gcc/cp/cp-trait.def                         |  1 +
>  gcc/cp/semantics.cc                         |  4 +++
>  gcc/testsuite/g++.dg/ext/has-builtin-1.C    |  3 ++
>  gcc/testsuite/g++.dg/ext/is_scalar.C        | 31 +++++++++++++++++++++
>  gcc/testsuite/g++.dg/tm/pr46567.C           | 10 +++----
>  gcc/testsuite/g++.dg/torture/pr57107.C      |  4 +--
>  libstdc++-v3/include/bits/cpp_type_traits.h |  2 +-
>  libstdc++-v3/include/bits/stl_algobase.h    |  8 +++---
>  libstdc++-v3/include/bits/valarray_array.h  |  2 +-
>  10 files changed, 55 insertions(+), 13 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/ext/is_scalar.C
>
> diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
> index 8cf0f2d0974..4c27f2a3a62 100644
> --- a/gcc/cp/constraint.cc
> +++ b/gcc/cp/constraint.cc
> @@ -3751,6 +3751,9 @@ diagnose_trait_expr (tree expr, tree args)
>      case CPTK_IS_UNION:
>        inform (loc, "  %qT is not a union", t1);
>        break;
> +    case CPTK_IS_SCALAR:
> +      inform (loc, "  %qT is not a scalar type", t1);
> +      break;
>      case CPTK_IS_AGGREGATE:
>        inform (loc, "  %qT is not an aggregate", t1);
>        break;
> diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
> index 8b7fece0cc8..59ae087c457 100644
> --- a/gcc/cp/cp-trait.def
> +++ b/gcc/cp/cp-trait.def
> @@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2)
>  DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1)
>  DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1)
>  DEFTRAIT_EXPR (IS_UNION, "__is_union", 1)
> +DEFTRAIT_EXPR (IS_SCALAR, "__is_scalar", 1)
>  DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2)
>  DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2)
>  /* FIXME Added space to avoid direct usage in GCC 13.  */
> diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
> index 8fb47fd179e..3edc7f23212 100644
> --- a/gcc/cp/semantics.cc
> +++ b/gcc/cp/semantics.cc
> @@ -12118,6 +12118,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
>      case CPTK_IS_UNION:
>        return type_code1 == UNION_TYPE;
>
> +    case CPTK_IS_SCALAR:
> +      return SCALAR_TYPE_P (type1);
> +
>      case CPTK_IS_ASSIGNABLE:
>        return is_xible (MODIFY_EXPR, type1, type2);
>
> @@ -12296,6 +12299,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2)
>      case CPTK_IS_ENUM:
>      case CPTK_IS_UNION:
>      case CPTK_IS_SAME:
> +    case CPTK_IS_SCALAR:
>        break;
>
>      case CPTK_IS_LAYOUT_COMPATIBLE:
> diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> index f343e153e56..75acbdfb9fc 100644
> --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> @@ -146,3 +146,6 @@
>  #if !__has_builtin (__remove_cvref)
>  # error "__has_builtin (__remove_cvref) failed"
>  #endif
> +#if !__has_builtin (__is_scalar)
> +# error "__has_builtin (__is_scalar) failed"
> +#endif
> diff --git a/gcc/testsuite/g++.dg/ext/is_scalar.C b/gcc/testsuite/g++.dg/ext/is_scalar.C
> new file mode 100644
> index 00000000000..457fddc52fc
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/ext/is_scalar.C
> @@ -0,0 +1,31 @@
> +// { dg-do compile { target c++11 } }
> +
> +#include <cstddef>  // std::nullptr_t
> +#include <testsuite_tr1.h>
> +
> +using namespace __gnu_test;
> +
> +#define SA(X) static_assert((X),#X)
> +
> +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT)  \
> +  SA(TRAIT(TYPE) == EXPECT);                                   \
> +  SA(TRAIT(const TYPE) == EXPECT);                             \
> +  SA(TRAIT(volatile TYPE) == EXPECT);                  \
> +  SA(TRAIT(const volatile TYPE) == EXPECT)
> +
> +// volatile return type would cause a warning.
> +#define SA_FN_TEST_CATEGORY(TRAIT, TYPE, EXPECT)       \
> +  SA(TRAIT(TYPE) == EXPECT);                                           \
> +  SA(TRAIT(const TYPE) == EXPECT)
> +
> +SA_TEST_CATEGORY(__is_scalar, int, true);
> +SA_TEST_CATEGORY(__is_scalar, float, true);
> +SA_TEST_CATEGORY(__is_scalar, EnumType, true);
> +SA_TEST_CATEGORY(__is_scalar, int*, true);
> +SA_FN_TEST_CATEGORY(__is_scalar, int(*)(int), true);
> +SA_TEST_CATEGORY(__is_scalar, int (ClassType::*), true);
> +SA_FN_TEST_CATEGORY(__is_scalar, int (ClassType::*) (int), true);
> +SA_TEST_CATEGORY(__is_scalar, std::nullptr_t, true);
> +
> +// Sanity check.
> +SA_TEST_CATEGORY(__is_scalar, ClassType, false);
> diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C
> index 6d791484448..d79e0afb462 100644
> --- a/gcc/testsuite/g++.dg/tm/pr46567.C
> +++ b/gcc/testsuite/g++.dg/tm/pr46567.C
> @@ -225,7 +225,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
>      : public __traitor<__is_void<_Tp>, __is_arithmetic<_Tp> >
>      { };
>    template<typename _Tp>
> -    struct __is_scalar
> +    struct ____is_scalar
>      : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >
>      { };
>    template<typename _Tp>
> @@ -1325,7 +1325,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
>      }
>    template<typename _ForwardIterator, typename _Tp>
>      inline typename
> -    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, void>::__type
> +    __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, void>::__type
>      __fill_a(_ForwardIterator __first, _ForwardIterator __last,
>         const _Tp& __value)
>      {
> @@ -1334,7 +1334,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
>      }
>    template<typename _ForwardIterator, typename _Tp>
>      inline typename
> -    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type
> +    __gnu_cxx::__enable_if<____is_scalar<_Tp>::__value, void>::__type
>      __fill_a(_ForwardIterator __first, _ForwardIterator __last,
>        const _Tp& __value)
>      {
> @@ -1362,7 +1362,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
>      }
>    template<typename _OutputIterator, typename _Size, typename _Tp>
>      inline typename
> -    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
> +    __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, _OutputIterator>::__type
>      __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
>      {
>        for (; __n > 0; --__n, ++__first)
> @@ -1371,7 +1371,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
>      }
>    template<typename _OutputIterator, typename _Size, typename _Tp>
>      inline typename
> -    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
> +    __gnu_cxx::__enable_if<____is_scalar<_Tp>::__value, _OutputIterator>::__type
>      __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
>      {
>        const _Tp __tmp = __value;
> diff --git a/gcc/testsuite/g++.dg/torture/pr57107.C b/gcc/testsuite/g++.dg/torture/pr57107.C
> index 4dbd32bd298..65fd74ded9a 100644
> --- a/gcc/testsuite/g++.dg/torture/pr57107.C
> +++ b/gcc/testsuite/g++.dg/torture/pr57107.C
> @@ -27,7 +27,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
>      };
>      template<typename _Tp>     struct __is_arithmetic     : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> >     {
>      };
> -    template<typename _Tp>     struct __is_scalar     : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >     {
> +    template<typename _Tp>     struct ____is_scalar     : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >     {
>      };
>  }
>  namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) {
> @@ -54,7 +54,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
>      };
>      template<typename _Iterator>     inline typename _Niter_base<_Iterator>::iterator_type     __niter_base(_Iterator __it)     {
>      }
> -    template<typename _OutputIterator, typename _Size, typename _Tp>     inline typename     __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type     __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)     {
> +    template<typename _OutputIterator, typename _Size, typename _Tp>     inline typename     __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, _OutputIterator>::__type     __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)     {
>         for (__decltype(__n + 0) __niter = __n;
>              __niter > 0;
>              --__niter, ++__first)  *__first = __value;
> diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h
> index 4312f32a4e0..f7f0d558421 100644
> --- a/libstdc++-v3/include/bits/cpp_type_traits.h
> +++ b/libstdc++-v3/include/bits/cpp_type_traits.h
> @@ -389,7 +389,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
>    // A scalar type is an arithmetic type or a pointer type
>    //
>    template<typename _Tp>
> -    struct __is_scalar
> +    struct ____is_scalar
>      : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >
>      { };
>
> diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h
> index dd95e94f7e9..f292d26fbf0 100644
> --- a/libstdc++-v3/include/bits/stl_algobase.h
> +++ b/libstdc++-v3/include/bits/stl_algobase.h
> @@ -911,7 +911,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
>    template<typename _ForwardIterator, typename _Tp>
>      _GLIBCXX20_CONSTEXPR
>      inline typename
> -    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, void>::__type
> +    __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, void>::__type
>      __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
>               const _Tp& __value)
>      {
> @@ -922,7 +922,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
>    template<typename _ForwardIterator, typename _Tp>
>      _GLIBCXX20_CONSTEXPR
>      inline typename
> -    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type
> +    __gnu_cxx::__enable_if<____is_scalar<_Tp>::__value, void>::__type
>      __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
>               const _Tp& __value)
>      {
> @@ -1060,7 +1060,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
>    template<typename _OutputIterator, typename _Size, typename _Tp>
>      _GLIBCXX20_CONSTEXPR
>      inline typename
> -    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
> +    __gnu_cxx::__enable_if<!____is_scalar<_Tp>::__value, _OutputIterator>::__type
>      __fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value)
>      {
>        for (; __n > 0; --__n, (void) ++__first)
> @@ -1071,7 +1071,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
>    template<typename _OutputIterator, typename _Size, typename _Tp>
>      _GLIBCXX20_CONSTEXPR
>      inline typename
> -    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
> +    __gnu_cxx::__enable_if<____is_scalar<_Tp>::__value, _OutputIterator>::__type
>      __fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value)
>      {
>        const _Tp __tmp = __value;
> diff --git a/libstdc++-v3/include/bits/valarray_array.h b/libstdc++-v3/include/bits/valarray_array.h
> index 222fd5fd900..682770ad7db 100644
> --- a/libstdc++-v3/include/bits/valarray_array.h
> +++ b/libstdc++-v3/include/bits/valarray_array.h
> @@ -90,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>      inline void
>      __valarray_default_construct(_Tp* __b, _Tp* __e)
>      {
> -      _Array_default_ctor<_Tp, __is_scalar<_Tp>::__value>::_S_do_it(__b, __e);
> +      _Array_default_ctor<_Tp, ____is_scalar<_Tp>::__value>::_S_do_it(__b, __e);
>      }
>
>    // Turn a raw-memory into an array of _Tp filled with __t
> --
> 2.41.0
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-09-04 15:01 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-03  9:13 [PATCH 1/2] c++, libstdc++: implement __is_scalar built-in trait Ken Matsui
2023-07-03  9:13 ` [PATCH 2/2] libstdc++: use new built-in trait __is_scalar for std::is_scalar Ken Matsui
2023-07-03 10:00 ` [PATCH 1/2] c++, libstdc++: implement __is_scalar built-in trait Ken Matsui
2023-07-08  4:45   ` [PATCH v2 " Ken Matsui
2023-07-08  4:45     ` [PATCH v2 2/2] libstdc++: use new built-in trait __is_scalar for std::is_scalar Ken Matsui
2023-07-12  9:50       ` Jonathan Wakely
2023-07-12 18:32         ` Ken Matsui
2023-07-12 18:56           ` Xi Ruoyao
2023-07-12 19:06             ` Ken Matsui
2023-07-12 19:23           ` Jonathan Wakely
2023-07-12 19:35             ` Ken Matsui
2023-09-04 15:00     ` [PING][PATCH v2 1/2] c++, libstdc++: implement __is_scalar built-in trait Ken Matsui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).