diff mbox

[C++] PR 61489

Message ID 54108E70.1030703@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Sept. 10, 2014, 5:46 p.m. UTC
Hi,

the bug (Jon, in fact) argues that probably we shouldn't 
-Wmissing-field-initializers warn for cases like obj11 below (or 
warn5.C). I noticed that in practice this is also the specific behavior 
which clang++ implements for their warning with the same name.

Tested x86_64-linux.

Thanks,
Paolo.

/////////////////////
/cp
2014-09-10  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/61489
	* typeck2.c (process_init_constructor_record): Do not warn about
	missing field initializer if EMPTY_CONSTRUCTOR_P (init).

/testsuite
2014-09-10  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/61489
	* g++.dg/warn/Wmissing-field-initializers-1.C: New.
	* g++.old-deja/g++.other/warn5.C: Adjust.

Comments

Jason Merrill Sept. 11, 2014, 3:06 p.m. UTC | #1
Do we need a documentation update?

Jason
diff mbox

Patch

Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c	(revision 215117)
+++ cp/typeck2.c	(working copy)
@@ -1359,7 +1359,8 @@  process_init_constructor_record (tree type, tree i
 	  next = massage_init_elt (TREE_TYPE (field), next, complain);
 
 	  /* Warn when some struct elements are implicitly initialized.  */
-	  if (complain & tf_warning)
+	  if ((complain & tf_warning)
+	      && !EMPTY_CONSTRUCTOR_P (init))
 	    warning (OPT_Wmissing_field_initializers,
 		     "missing initializer for member %qD", field);
 	}
@@ -1382,7 +1383,8 @@  process_init_constructor_record (tree type, tree i
 
 	  /* Warn when some struct elements are implicitly initialized
 	     to zero.  */
-	  if (complain & tf_warning)
+	  if ((complain & tf_warning)
+	      && !EMPTY_CONSTRUCTOR_P (init))
 	    warning (OPT_Wmissing_field_initializers,
 		     "missing initializer for member %qD", field);
 
Index: testsuite/g++.dg/warn/Wmissing-field-initializers-1.C
===================================================================
--- testsuite/g++.dg/warn/Wmissing-field-initializers-1.C	(revision 0)
+++ testsuite/g++.dg/warn/Wmissing-field-initializers-1.C	(working copy)
@@ -0,0 +1,31 @@ 
+// PR c++/61489
+// { dg-options "-Wmissing-field-initializers" }
+
+struct mystruct1 {
+  int a, b;
+};
+
+struct aux2 {
+  aux2();
+};
+
+struct mystruct2 {
+  aux2 a, b;
+};
+
+struct aux3 {
+  int x;
+};
+
+struct mystruct3 {
+  aux3 a, b;
+};
+
+mystruct1 obj11 = {};
+mystruct1 obj12 = {0};       // { dg-warning "missing field initializer" }
+
+mystruct2 obj21 = {};
+mystruct2 obj22 = {aux2()};  // { dg-warning "missing field initializer" }
+
+mystruct3 obj31 = {};
+mystruct3 obj32 = {0};       // { dg-warning "missing field initializer" }
Index: testsuite/g++.old-deja/g++.other/warn5.C
===================================================================
--- testsuite/g++.old-deja/g++.other/warn5.C	(revision 215117)
+++ testsuite/g++.old-deja/g++.other/warn5.C	(working copy)
@@ -16,4 +16,4 @@  X *foo ()
   return new X ();  // gets bogus warning
 }
 
-X x = {};           // { dg-warning "" } missing initializer
+X x = {};