From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19636 invoked by alias); 3 Feb 2012 12:34:46 -0000 Received: (qmail 19478 invoked by uid 22791); 3 Feb 2012 12:34:46 -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 12:34:31 +0000 From: "vincent-gcc at vinc17 dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/52106] New: missing -Wunused-but-set-variable warning with the a = b = ... construct Date: Fri, 03 Feb 2012 12:34:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new 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: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" 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/msg00350.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52106 Bug #: 52106 Summary: missing -Wunused-but-set-variable warning with the a = b = ... construct Classification: Unclassified Product: gcc Version: unknown Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: vincent-gcc@vinc17.net The following code int foo (void) { int a, b, c, d; a = b = 0; c = d = 0; return a + d; } gives: $ gcc-snapshot -Wall -c tst.c tst.c: In function 'foo': tst.c:3:13: warning: variable 'c' set but not used [-Wunused-but-set-variable] One would expect the same warning for variable 'b'. Even though it appears to be used to assign variable 'a', it shouldn't count in such a construct. Indeed a variable assignment is useless if the variable isn't used in a later expression (if the goal is to convert the value, then a cast would be more readable). Tested with: gcc (Debian 20120128-1) 4.7.0 20120128 (experimental) [trunk revision 183664]