From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1164 invoked by alias); 21 Jan 2015 14:10:01 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 1096 invoked by uid 48); 21 Jan 2015 14:09:51 -0000 From: "mpolacek at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/64709] [5 Regression] Bogus -Wmissing-field-initializers warning Date: Wed, 21 Jan 2015 14:10:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 5.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mpolacek at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 5.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-01/txt/msg02212.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64709 --- Comment #4 from Marek Polacek --- 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