This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/52106] New: missing -Wunused-but-set-variable warning with the a = b = ... construct


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]


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]