public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/64709] Bogus -Wmissing-field-initializers warning
       [not found] <bug-64709-4@http.gcc.gnu.org/bugzilla/>
@ 2015-01-21 12:32 ` mpolacek at gcc dot gnu.org
  2015-01-21 12:49 ` [Bug c/64709] [5 Regression] " mpolacek at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-01-21 12:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64709

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
We shouldn't warn on { 0 }.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/64709] [5 Regression] Bogus -Wmissing-field-initializers warning
       [not found] <bug-64709-4@http.gcc.gnu.org/bugzilla/>
  2015-01-21 12:32 ` [Bug c/64709] Bogus -Wmissing-field-initializers warning mpolacek at gcc dot gnu.org
@ 2015-01-21 12:49 ` mpolacek at gcc dot gnu.org
  2015-01-21 13:15 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-01-21 12:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64709

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |5.0
            Summary|Bogus                       |[5 Regression] Bogus
                   |-Wmissing-field-initializer |-Wmissing-field-initializer
                   |s warning                   |s warning


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/64709] [5 Regression] Bogus -Wmissing-field-initializers warning
       [not found] <bug-64709-4@http.gcc.gnu.org/bugzilla/>
  2015-01-21 12:32 ` [Bug c/64709] Bogus -Wmissing-field-initializers warning mpolacek at gcc dot gnu.org
  2015-01-21 12:49 ` [Bug c/64709] [5 Regression] " mpolacek at gcc dot gnu.org
@ 2015-01-21 13:15 ` jakub at gcc dot gnu.org
  2015-01-21 13:28 ` mpolacek at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-01-21 13:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64709

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jsm28 at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I wonder if that might not be undesirable in some cases, perhaps allow the
users to choose?  -Wmissing-field-initializers ==
-Wmissing-field-initializers=1 (enabled in -Wall or where) would do what you
suggest, -Wmissing-field-initializers=2 would warn even for this?


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/64709] [5 Regression] Bogus -Wmissing-field-initializers warning
       [not found] <bug-64709-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2015-01-21 13:15 ` jakub at gcc dot gnu.org
@ 2015-01-21 13:28 ` mpolacek at gcc dot gnu.org
  2015-01-21 14:10 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-01-21 13:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64709

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-01-21
     Ever confirmed|0                           |1

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Maybe.  There's an RFE for -Wmissing-field-initializers=2 in PR39589, though
that speaks about allowing the warning with designated initializers.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/64709] [5 Regression] Bogus -Wmissing-field-initializers warning
       [not found] <bug-64709-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2015-01-21 13:28 ` mpolacek at gcc dot gnu.org
@ 2015-01-21 14:10 ` mpolacek at gcc dot gnu.org
  2015-01-21 14:15 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-01-21 14:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64709

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
BTW, untested patch (dg.exp passes).  

diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index f39dfdd..53d1a16 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -7556,20 +7556,28 @@ pop_init_level (location_t loc, int implicit,
     }
     }

-  /* Initialization with { } counts as zeroinit.  */
-  if (vec_safe_length (constructor_elements) == 0)
-    constructor_zeroinit = 1;
-  /* If the constructor has more than one element, it can't be { 0 }.  */
-  else if (vec_safe_length (constructor_elements) != 1)
-    constructor_zeroinit = 0;
+  switch (vec_safe_length (constructor_elements))
+    {
+    case 0:
+      /* Initialization with { } counts as zeroinit.  */
+      constructor_zeroinit = 1;
+      break;
+    case 1:
+      /* This might be zeroinit as well.  */
+      if (integer_zerop ((*constructor_elements)[0].value))
+    constructor_zeroinit = 1;
+      break;
+    default:
+      /* If the constructor has more than one element, it can't be { 0 }.  */
+      constructor_zeroinit = 0;
+      break;
+    }

   /* Warn when some structs are initialized with direct aggregation.  */
   if (!implicit && found_missing_braces && warn_missing_braces
       && !constructor_zeroinit)
-    {
-      warning_init (loc, OPT_Wmissing_braces,
-            "missing braces around initializer");
-    }
+    warning_init (loc, OPT_Wmissing_braces,
+          "missing braces around initializer");

   /* Warn when some struct elements are implicitly initialized to zero.  */
   if (warn_missing_field_initializers


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/64709] [5 Regression] Bogus -Wmissing-field-initializers warning
       [not found] <bug-64709-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2015-01-21 14:10 ` mpolacek at gcc dot gnu.org
@ 2015-01-21 14:15 ` jakub at gcc dot gnu.org
  2015-01-29 21:03 ` mpolacek at gcc dot gnu.org
  2015-01-29 21:03 ` mpolacek at gcc dot gnu.org
  7 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-01-21 14:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64709

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
What value will constructor_zeroinit have if it has a single element which is
not integer_zerop?  Should we set it to 0 in that case?


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/64709] [5 Regression] Bogus -Wmissing-field-initializers warning
       [not found] <bug-64709-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2015-01-21 14:15 ` jakub at gcc dot gnu.org
@ 2015-01-29 21:03 ` mpolacek at gcc dot gnu.org
  2015-01-29 21:03 ` mpolacek at gcc dot gnu.org
  7 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-01-29 21:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64709

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Thu Jan 29 21:02:21 2015
New Revision: 220263

URL: https://gcc.gnu.org/viewcvs?rev=220263&root=gcc&view=rev
Log:
    PR c/64709
    * c-typeck.c (pop_init_level): If constructor_elements has
    exactly one element with integer_zerop value, set constructor_zeroinit
    to 1.  Remove braces around warning_init call.

    * gcc.dg/pr64709.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr64709.c
Modified:
    trunk/gcc/c/ChangeLog
    trunk/gcc/c/c-typeck.c
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/64709] [5 Regression] Bogus -Wmissing-field-initializers warning
       [not found] <bug-64709-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2015-01-29 21:03 ` mpolacek at gcc dot gnu.org
@ 2015-01-29 21:03 ` mpolacek at gcc dot gnu.org
  7 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-01-29 21:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64709

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-01-29 21:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-64709-4@http.gcc.gnu.org/bugzilla/>
2015-01-21 12:32 ` [Bug c/64709] Bogus -Wmissing-field-initializers warning mpolacek at gcc dot gnu.org
2015-01-21 12:49 ` [Bug c/64709] [5 Regression] " mpolacek at gcc dot gnu.org
2015-01-21 13:15 ` jakub at gcc dot gnu.org
2015-01-21 13:28 ` mpolacek at gcc dot gnu.org
2015-01-21 14:10 ` mpolacek at gcc dot gnu.org
2015-01-21 14:15 ` jakub at gcc dot gnu.org
2015-01-29 21:03 ` mpolacek at gcc dot gnu.org
2015-01-29 21:03 ` mpolacek at gcc dot gnu.org

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).