[PATCH] libstdc++: Fix up std::is_scalar for std::meta::info [PR125024]
Jonathan Wakely
jwakely@redhat.com
Mon Apr 27 08:59:45 GMT 2026
On Mon, 27 Apr 2026 at 09:05, Jakub Jelinek <jakub@redhat.com> wrote:
>
> Hi!
>
> https://eel.is/c++draft/basic.types.general#9.sentence-1 says that
> std::meta::info and its cv-qualified versions are scalar types too
> (and in https://eel.is/c++draft/basic.fundamental#19.sentence-1
> that they are fundamental types too).
> Now, on the reflection side, eval_is_scalar_type is handled
> in the compiler and uses SCALAR_TYPE_P (type) which includes
> REFLECTION_TYPE_P check and eval_is_fundamental_type includes that
> explicitly too.
> std::is_fundamental uses
> template<typename _Tp>
> struct is_fundamental
> : public __or_<is_arithmetic<_Tp>, is_void<_Tp>,
> is_null_pointer<_Tp>
> #if __cpp_impl_reflection >= 202506L
> , is_reflection<_Tp>
> #endif
> >::type
> { };
> but for std::is_scalar we apparently forgot to include is_reflection.
>
> The following patch fixes that.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/16.2?
OK for both.
is_scalar is one of the more expensive traits and it would be good to
have a builtin for it some day.
>
> 2026-04-26 Jakub Jelinek <jakub@redhat.com>
>
> PR libstdc++/125024
> * include/std/type_traits (std::is_scalar): For
> __cpp_impl_reflection >= 202506L handle is_reflection types as
> scalar.
> * testsuite/20_util/is_scalar/reflection.cc: New test.
>
> --- libstdc++-v3/include/std/type_traits.jj 2026-04-09 18:09:11.002020134 +0200
> +++ libstdc++-v3/include/std/type_traits 2026-04-26 19:20:37.109205308 +0200
> @@ -871,7 +871,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> 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
> + is_member_pointer<_Tp>, is_null_pointer<_Tp>
> +#if __cpp_impl_reflection >= 202506L
> + , is_reflection<_Tp>
> +#endif
> + >::type
> { };
>
> /// is_compound
> --- libstdc++-v3/testsuite/20_util/is_scalar/reflection.cc.jj 2026-04-26 20:30:15.661943601 +0200
> +++ libstdc++-v3/testsuite/20_util/is_scalar/reflection.cc 2026-04-26 20:49:40.107965736 +0200
> @@ -0,0 +1,13 @@
> +// { dg-do compile { target c++26 } }
> +// { dg-additional-options "-freflection" }
> +
> +#include <type_traits>
> +#include <testsuite_tr1.h>
> +
> +void test01()
> +{
> + using std::is_scalar;
> + using namespace __gnu_test;
> +
> + static_assert(test_category<is_scalar, decltype (^^::)>(true), "");
> +}
>
> Jakub
>
More information about the Libstdc++
mailing list