public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>, Jason Merrill <jason@redhat.com>
Cc: Patrick Palka <ppalka@redhat.com>
Subject: [PATCH] c++: -Wmissing-field-initializers and empty class [PR110064]
Date: Wed, 19 Jul 2023 15:20:47 -0400	[thread overview]
Message-ID: <20230719192047.449259-1-polacek@redhat.com> (raw)

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

-- >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
-- 
2.41.0


             reply	other threads:[~2023-07-19 19:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-19 19:20 Marek Polacek [this message]
2023-07-19 19:36 ` Jason Merrill
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=20230719192047.449259-1-polacek@redhat.com \
    --to=polacek@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@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).