From: Jason Merrill <jason@redhat.com>
To: Marek Polacek <polacek@redhat.com>,
GCC Patches <gcc-patches@gcc.gnu.org>
Cc: Patrick Palka <ppalka@redhat.com>
Subject: Re: [PATCH] c++: -Wmissing-field-initializers and empty class [PR110064]
Date: Wed, 19 Jul 2023 15:36:49 -0400 [thread overview]
Message-ID: <f046ec6b-f484-717d-4642-6cae9ebf7009@redhat.com> (raw)
In-Reply-To: <20230719192047.449259-1-polacek@redhat.com>
On 7/19/23 15:20, Marek Polacek wrote:
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
OK. We might also improve the diagnostic for base classes, perhaps by
teaching dump_simple_decl about DECL_FIELD_IS_BASE?
> -- >8 --
>
> Let's suppress -Wmissing-field-initializers for empty classes.
>
> Here I don't think I need the usual COMPLETE_TYPE_P/dependent_type_p
> checks.
>
> PR c++/110064
>
> gcc/cp/ChangeLog:
>
> * typeck2.cc (process_init_constructor_record): Don't emit
> -Wmissing-field-initializers for empty classes.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/warn/Wmissing-field-initializers-3.C: New test.
> ---
> gcc/cp/typeck2.cc | 3 +-
> .../warn/Wmissing-field-initializers-3.C | 48 +++++++++++++++++++
> 2 files changed, 50 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/g++.dg/warn/Wmissing-field-initializers-3.C
>
> diff --git a/gcc/cp/typeck2.cc b/gcc/cp/typeck2.cc
> index 1c204c8612b..582a73bb053 100644
> --- a/gcc/cp/typeck2.cc
> +++ b/gcc/cp/typeck2.cc
> @@ -1874,7 +1874,8 @@ process_init_constructor_record (tree type, tree init, int nested, int flags,
> to zero. */
> if ((complain & tf_warning)
> && !cp_unevaluated_operand
> - && !EMPTY_CONSTRUCTOR_P (init))
> + && !EMPTY_CONSTRUCTOR_P (init)
> + && !is_really_empty_class (fldtype, /*ignore_vptr*/false))
> warning (OPT_Wmissing_field_initializers,
> "missing initializer for member %qD", field);
>
> diff --git a/gcc/testsuite/g++.dg/warn/Wmissing-field-initializers-3.C b/gcc/testsuite/g++.dg/warn/Wmissing-field-initializers-3.C
> new file mode 100644
> index 00000000000..a8d75b92bd1
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/warn/Wmissing-field-initializers-3.C
> @@ -0,0 +1,48 @@
> +// PR c++/110064
> +// { dg-do compile { target c++17 } }
> +// { dg-options "-Wmissing-field-initializers" }
> +
> +struct B { };
> +struct D : B {
> + int x;
> + int y;
> +};
> +
> +struct E {
> + int x;
> + int y;
> + B z;
> +};
> +
> +template<typename> struct X { };
> +
> +template<typename T>
> +struct F {
> + int i;
> + int j;
> + X<T> x;
> +};
> +
> +int
> +main ()
> +{
> + D d = {.x=1, .y=2}; // { dg-bogus "missing" }
> + (void)d;
> + E e = {.x=1, .y=2}; // { dg-bogus "missing" }
> + (void)e;
> + F<int> f = {.i=1, .j=2 }; // { dg-bogus "missing" }
> + (void)f;
> +}
> +
> +template<typename T>
> +void fn ()
> +{
> + F<T> f = {.i=1, .j=2 }; // { dg-bogus "missing" }
> + (void)f;
> +}
> +
> +void
> +g ()
> +{
> + fn<int> ();
> +}
>
> base-commit: 2971ff7b1d564ac04b537d907c70e6093af70832
next prev parent reply other threads:[~2023-07-19 19:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-19 19:20 Marek Polacek
2023-07-19 19:36 ` Jason Merrill [this message]
2023-07-19 19:40 ` Marek Polacek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f046ec6b-f484-717d-4642-6cae9ebf7009@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=polacek@redhat.com \
--cc=ppalka@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).