From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B1574385701D; Tue, 18 Jul 2023 22:59:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B1574385701D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689721187; bh=dg89TwJYgqYK3jv7wPw2mjbEwSpP67ak3IAW2ku5JBE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Fi2kjXnGCwCoRXx+2V12z29AA7+UMGknENnewX1lmU06zI3k2frCacBuqcE78ecTS pzOoZGgyB7PD8tGWyh/OTnO3jNW4/AgAb64KNKPIcXVBO+w9X8Q8/T7+oR6S5eCTIH ymWpsyXZHykmfE9vsZMl5EhF23zkckeGafKjizwg= From: "vincent-gcc at vinc17 dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/44677] Warn for variables incremented but not used (+=, ++) Date: Tue, 18 Jul 2023 22:59:45 +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: 4.5.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: vincent-gcc at vinc17 dot net X-Bugzilla-Status: NEW X-Bugzilla-Resolution: 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: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D44677 Vincent Lef=C3=A8vre changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |vincent-gcc at vinc17 dot = net --- Comment #17 from Vincent Lef=C3=A8vre -= -- (In reply to Martin Sebor from comment #10) > $ cat pr95217.c && clang -S -Wall -Wextra --analyze pr95217.c [...] > pr95217.c:8:3: warning: Value stored to 'p' is never read > p +=3D 1; // missing warning > ^ ~ > pr95217.c:13:3: warning: Value stored to 'p' is never read > p =3D p + 1; // missing warning > ^ ~~~~~ > 2 warnings generated. Clang (15 and above) with -Wunused-but-set-variable now detects the issue on the "p++" and "p +=3D 1" forms (ditto with other combined assignment operat= ors), but not on "p =3D p + 1". Such forms (p++, etc.) are common, so that detecting an unused variable is = very useful. Like Paul did for Emacs (comment 13), I've just fixed two issues in GNU MPFR (one cosmetic about a useless loop variable and one important in the testsuite), found with Clang 16. The references: https://gitlab.inria.fr/mpfr/mpfr/-/commit/4c110cf4773b3c07de2a33acbee591ce= db083c80 https://gitlab.inria.fr/mpfr/mpfr/-/commit/b34d867fa41934d12d0d4dbaaa0242d6= d3eb32c7 For the second MPFR issue, there was an "err++" for each error found by the function in the testsuite, but err was not tested at the end, so that poten= tial errors were never reported.=