From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18933 invoked by alias); 20 Jan 2015 09:32:42 -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 18837 invoked by uid 48); 20 Jan 2015 09:32:36 -0000 From: "maltsevm at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/64639] false negative of -Wunused-value Date: Tue, 20 Jan 2015 09:32: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: maltsevm at gmail dot com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc 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/msg01987.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64639 Mikhail Maltsev changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |maltsevm at gmail dot com --- Comment #5 from Mikhail Maltsev --- > gets somehow transformed into > b = (a = 0B) != 0B;, 0; Probably folding works this way. Anyway, I think, I can explain how the warning is [not] generated (I stepped through the code using GDB). So: We start parsing RHS of assignment expression (the outermost one). After parsing two operands of comma, we get into build_compound_expr function (in c-typeck.c) and this function generates a warning because "left-hand operand of comma expression" (i.e. 0) "has no effect" (that's true, but the wording is a bit strange). Then we parse the next comma expression and get into the same function. The code of build_compound_expr looks like this: ... if (!TREE_SIDE_EFFECTS (expr1)) ... else if (TREE_CODE (expr1) == COMPOUND_EXPR && warn_unused_value) ... /* With -Wunused, we should also warn if the left-hand operand does have side-effects, but computes a value which is not used. For example, in `foo() + bar(), baz()' the result of the `+' operator is not used, so we should issue a warning. */ else if (warn_unused_value) warn_if_unused_value (expr1, loc); Unfortunately, we don't get into warn_if_unused_value because the condition of previous branch is true. That's why there is no warning about the result of comparison. P.S. I know, that it all might be obvious for most of you, but I'm just trying to get acquainted with GCC sources and (hopefully) do something useful for the project, while waiting for next stage1 (bugs being fixed during stage 4 are obviously not for newcomers).