public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/52106] New: missing -Wunused-but-set-variable warning with the a = b = ... construct
@ 2012-02-03 12:34 vincent-gcc at vinc17 dot net
  2012-02-03 12:54 ` [Bug c/52106] " jakub at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2012-02-03 12:34 UTC (permalink / raw)
  To: gcc-bugs

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]


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/52106] missing -Wunused-but-set-variable warning with the a = b = ... construct
  2012-02-03 12:34 [Bug c/52106] New: missing -Wunused-but-set-variable warning with the a = b = ... construct vincent-gcc at vinc17 dot net
@ 2012-02-03 12:54 ` jakub at gcc dot gnu.org
  2012-02-03 13:29 ` [Bug c/52106] warning for useless assignments vincent-gcc at vinc17 dot net
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-02-03 12:54 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52106

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |jakub at gcc dot gnu.org
         Resolution|                            |INVALID

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-02-03 12:53:42 UTC ---
The variable is used, so it isn't unused-but-set.  It is intentional that the
warning behaves the way it does.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/52106] warning for useless assignments
  2012-02-03 12:34 [Bug c/52106] New: missing -Wunused-but-set-variable warning with the a = b = ... construct vincent-gcc at vinc17 dot net
  2012-02-03 12:54 ` [Bug c/52106] " jakub at gcc dot gnu.org
@ 2012-02-03 13:29 ` vincent-gcc at vinc17 dot net
  2012-02-03 13:33 ` rguenth at gcc dot gnu.org
  2012-02-03 17:18 ` [Bug c/52106] [C11] missing -Wunused-but-set-variable warning with the a = b = ... construct pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2012-02-03 13:29 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52106

Vincent Lefèvre <vincent-gcc at vinc17 dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |
            Summary|missing                     |warning for useless
                   |-Wunused-but-set-variable   |assignments
                   |warning with the a = b =    |
                   |... construct               |

--- Comment #2 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> 2012-02-03 13:28:39 UTC ---
Then there should be another warning. So, this is a request for a warning for
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 = b = 0;
  return a;
}

gives an example. It could be written:

int foo (void)
{
  int a;
  a = 0;
  return a;
}

"a = b = ...;" is generally used as a shortcut for "a = ...; b = ...;", 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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/52106] warning for useless assignments
  2012-02-03 12:34 [Bug c/52106] New: missing -Wunused-but-set-variable warning with the a = b = ... construct vincent-gcc at vinc17 dot net
  2012-02-03 12:54 ` [Bug c/52106] " jakub at gcc dot gnu.org
  2012-02-03 13:29 ` [Bug c/52106] warning for useless assignments vincent-gcc at vinc17 dot net
@ 2012-02-03 13:33 ` rguenth at gcc dot gnu.org
  2012-02-03 17:18 ` [Bug c/52106] [C11] missing -Wunused-but-set-variable warning with the a = b = ... construct pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-02-03 13:33 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52106

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-02-03
     Ever Confirmed|0                           |1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/52106] [C11] missing -Wunused-but-set-variable warning with the a = b = ... construct
  2012-02-03 12:34 [Bug c/52106] New: missing -Wunused-but-set-variable warning with the a = b = ... construct vincent-gcc at vinc17 dot net
                   ` (2 preceding siblings ...)
  2012-02-03 13:33 ` rguenth at gcc dot gnu.org
@ 2012-02-03 17:18 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-02-03 17:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52106

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|warning for useless         |[C11] missing
                   |assignments                 |-Wunused-but-set-variable
                   |                            |warning with the a = b =
                   |                            |... construct

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-02-03 17:18:13 UTC ---
>  a = b = 0;

In C99 and before is equivalent to b = 0; a = b;
In C11 (which we don't implement this semantics yet), it is a = 0; b = 0;


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-02-03 17:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-03 12:34 [Bug c/52106] New: missing -Wunused-but-set-variable warning with the a = b = ... construct vincent-gcc at vinc17 dot net
2012-02-03 12:54 ` [Bug c/52106] " jakub at gcc dot gnu.org
2012-02-03 13:29 ` [Bug c/52106] warning for useless assignments vincent-gcc at vinc17 dot net
2012-02-03 13:33 ` rguenth at gcc dot gnu.org
2012-02-03 17:18 ` [Bug c/52106] [C11] missing -Wunused-but-set-variable warning with the a = b = ... construct pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).