On Thu, Jun 18, 2026 at 05:22:42PM -0400, Marek Polacek wrote:
> On Thu, Jun 18, 2026 at 04:37:44PM -0400, Jason Merrill wrote:
> > On 6/18/26 3:20 PM, Marek Polacek wrote:
> > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/16?
> > >
> > > -- >8 --
> > > Currently, we include all the built-ins like __builtin_fdimf32x in
> > > the result of members_of. We probably should skip them. This patch
> > > uses DECL_IS_UNDECLARED_BUILTIN so that we skip __builtin_abs but
> > > include abs.
> > >
> > > On ^^:: this reduces the # of elements from 2591 to 653.
> > >
> > > PR c++/125819
> > >
> > > gcc/cp/ChangeLog:
> > >
> > > * reflect.cc (namespace_members_of): Skip
> > > DECL_IS_UNDECLARED_BUILTIN functions.
> >
> > Why only functions? I'd think we want to skip all kinds of built-in decls.
>
> I can check all DECLs then. That filters out __builtin_va_list and
> __builtin_sysv_va_list too. This still leaves things like __fpos_t
> from /usr/include/bits/types/__fpos_t.h but I think it's up to us to
> decide if we want to include it or not.
Sounds like earlier today we concluded that we'd go ahead with this,
see if any user actually cares. So, ok for trunk?
> dg.exp=reflect/* passed.
>
> -- >8 --
> Currently, we include all the built-ins like __builtin_fdimf32x in
> the result of members_of. We probably should skip them. This patch
> uses DECL_IS_UNDECLARED_BUILTIN so that we skip __builtin_abs but
> include abs.
>
> On ^^:: this reduces the # of elements from 2591 to 651.
>
> PR c++/125819
>
> gcc/cp/ChangeLog:
>
> * reflect.cc (namespace_members_of): Skip
> DECL_IS_UNDECLARED_BUILTIN decls.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/reflect/members_of16.C: New test.
> ---
> gcc/cp/reflect.cc | 4 ++++
> gcc/testsuite/g++.dg/reflect/members_of16.C | 24 +++++++++++++++++++++
> 2 files changed, 28 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/reflect/members_of16.C
>
> diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc
> index 8dccf5e99a0..b582d0f5ed5 100644
> --- a/gcc/cp/reflect.cc
> +++ b/gcc/cp/reflect.cc
> @@ -6904,6 +6904,10 @@ namespace_members_of (location_t loc, tree ns)
> return;
> }
>
> + /* Skip GCC built-ins. */
> + if (DECL_P (b) && DECL_IS_UNDECLARED_BUILTIN (b))
> + return;
> +
> /* eval_is_accessible should be always true for namespace members,
> so don't bother calling it here. */
> CONSTRUCTOR_APPEND_ELT (data->elts, NULL_TREE,
> diff --git a/gcc/testsuite/g++.dg/reflect/members_of16.C
> b/gcc/testsuite/g++.dg/reflect/members_of16.C
> new file mode 100644
> index 00000000000..ea84b397091
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/reflect/members_of16.C
> @@ -0,0 +1,24 @@
> +// PR c++/125819
> +// { dg-do compile { target c++26 } }
> +// { dg-additional-options "-freflection" }
> +
> +#include <cstdlib>
> +#include <meta>
> +
> +consteval bool
> +check ()
> +{
> + bool found = false;
> + for (auto m : members_of (^^::, std::meta::access_context::current ()))
> + if (has_identifier (m))
> + {
> + if (identifier_of (m) == "__builtin_abs"
> + || identifier_of (m) == "__builtin_va_list")
> + return false;
> + if (identifier_of (m) == "abs")
> + found = true;
> + }
> + return found;
> +}
> +
> +static_assert (check ());
>
> base-commit: ecf1a808a41c4fc48eea886e00984eda17a0cdc3
> --
> 2.54.0
>
Marek