From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31437 invoked by alias); 3 Feb 2012 13:29:23 -0000 Received: (qmail 31428 invoked by uid 22791); 3 Feb 2012 13:29:23 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 03 Feb 2012 13:29:11 +0000 From: "vincent-gcc at vinc17 dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/52106] warning for useless assignments Date: Fri, 03 Feb 2012 13:29: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-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: vincent-gcc at vinc17 dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Status Resolution Summary Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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 X-SW-Source: 2012-02/txt/msg00358.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D52106 Vincent Lef=C3=A8vre changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |UNCONFIRMED Resolution|INVALID | Summary|missing |warning for useless |-Wunused-but-set-variable |assignments |warning with the a =3D b =3D | |... construct | --- Comment #2 from Vincent Lef=C3=A8vre 20= 12-02-03 13:28:39 UTC --- Then there should be another warning. So, this is a request for a warning f= or assignments that are obviously useless (thus maybe a typo in the code or old code that could be removed...). It should cover variables set but not used outside the full expression where they are set. The code int foo (void) { int a, b; a =3D b =3D 0; return a; } gives an example. It could be written: int foo (void) { int a; a =3D 0; return a; } "a =3D b =3D ...;" is generally used as a shortcut for "a =3D ...; b =3D ..= .;", and if it isn't (because the behavior would be different at compile time or at run time), there should be a warning against this construct.