[PATCH] c++/reflection: bogus -Wmissing-field-initializers with <meta> [PR124950]

Tim Song t.canens.cpp@gmail.com
Tue Apr 21 01:42:50 GMT 2026


Might be better to leave out the initializer for name since not specifying
it is pretty unusual? That matches what Barry proposed in some version of
P3795 before it was removed in an LWG telecon (for lack of normative
effect).

On Mon, Apr 20, 2026 at 4:46 PM Marek Polacek <polacek@redhat.com> wrote:

> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
>
> -- >8 --
> We emit -Wmissing-field-initializers warnings for code like
>
>   data_member_spec (^^int, { .name = "dms" })
>
> which seems undesirable.  We can initialize the members of
> std::meta::data_member_options to suppress that warning (clang's <meta>
> has these initializers too).
>
>         PR c++/124950
>
> libstdc++-v3/ChangeLog:
>
>         * include/std/meta (std::meta::data_member_options): Initialize
>         name, alignment, bit_width, and annotations members.
>
> gcc/testsuite/ChangeLog:
>
>         * g++.dg/reflect/data_member_spec7.C: New test.
> ---
>  gcc/testsuite/g++.dg/reflect/data_member_spec7.C | 8 ++++++++
>  libstdc++-v3/include/std/meta                    | 8 ++++----
>  2 files changed, 12 insertions(+), 4 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/reflect/data_member_spec7.C
>
> diff --git a/gcc/testsuite/g++.dg/reflect/data_member_spec7.C
> b/gcc/testsuite/g++.dg/reflect/data_member_spec7.C
> new file mode 100644
> index 00000000000..bdcdb1ee773
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/reflect/data_member_spec7.C
> @@ -0,0 +1,8 @@
> +// PR c++/124950
> +// { dg-do compile { target c++26 } }
> +// { dg-additional-options "-freflection -Wmissing-field-initializers" }
> +// Test that we don't emit bogus -Wmissing-field-initializers warnings.
> +
> +#include <meta>
> +using namespace std::meta;
> +constexpr auto dms = data_member_spec (^^int, { .name = "dms" });
> diff --git a/libstdc++-v3/include/std/meta b/libstdc++-v3/include/std/meta
> index 22b4da44cdd..69016a621ef 100644
> --- a/libstdc++-v3/include/std/meta
> +++ b/libstdc++-v3/include/std/meta
> @@ -423,11 +423,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>         info _M_unused = {};
>        };
>
> -      optional<_Name> name;
> -      optional<int> alignment;
> -      optional<int> bit_width;
> +      optional<_Name> name = nullopt;
> +      optional<int> alignment = nullopt;
> +      optional<int> bit_width = nullopt;
>        bool no_unique_address = false;
> -      vector<info> annotations;
> +      vector<info> annotations = {};
>      };
>      consteval info data_member_spec(info, data_member_options);
>      consteval bool is_data_member_spec(info);
>
> base-commit: 416fe77efb4ff6adf39c3326d462161217b75b42
> --
> 2.53.0
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20260420/838cb6af/attachment.htm>


More information about the Libstdc++ mailing list