public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/36390]  New: Unused variable warning should be more useful
@ 2008-05-30 13:17 jmfo1982 at yahoo dot es
  2008-08-14 23:33 ` [Bug c/36390] " eugene dot zelenko at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: jmfo1982 at yahoo dot es @ 2008-05-30 13:17 UTC (permalink / raw)
  To: gcc-bugs

gcc and g++ (all the versions I've ever used) don't give unused variable
warnings in a lot of cases where there are unused variables. Simple sample
code:

int test1 ()
{
  int x = 3;
  return (2);
}

int test2 ()
{
  int x;
  x = 3;
  return (2);
}

They only give an unused variable warning in test1 function. They should warn
in both cases.


-- 
           Summary: Unused variable warning should be more useful
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jmfo1982 at yahoo dot es


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


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

* [Bug c/36390] Unused variable warning should be more useful
  2008-05-30 13:17 [Bug c/36390] New: Unused variable warning should be more useful jmfo1982 at yahoo dot es
@ 2008-08-14 23:33 ` eugene dot zelenko at gmail dot com
  2009-02-12 14:33 ` [Bug c/36390] do not mark as used variables used only as lvalue manu at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: eugene dot zelenko at gmail dot com @ 2008-08-14 23:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from eugene dot zelenko at gmail dot com  2008-08-14 23:32 -------
I think unused variable warning should be expanded for all cases where variable
used only as lvalue. As result some useless computations could be avoided.

Coverity Prevent warn about such situations with one of its checkers. But
Coverity is too huge and slow tool, so GCC could definitely be better for such
diagnostics.


-- 

eugene dot zelenko at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eugene dot zelenko at gmail
                   |                            |dot com


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


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

* [Bug c/36390] do not mark as used variables used only as lvalue
  2008-05-30 13:17 [Bug c/36390] New: Unused variable warning should be more useful jmfo1982 at yahoo dot es
  2008-08-14 23:33 ` [Bug c/36390] " eugene dot zelenko at gmail dot com
@ 2009-02-12 14:33 ` manu at gcc dot gnu dot org
  2009-11-24  8:10 ` jakub at gcc dot gnu dot org
  2009-11-24 11:37 ` jakub at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-02-12 14:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from manu at gcc dot gnu dot org  2009-02-12 14:33 -------
I think this is a reasonable request. Confirmed.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |diagnostic
   Last reconfirmed|0000-00-00 00:00:00         |2009-02-12 14:33:07
               date|                            |
            Summary|Unused variable warning     |do not mark as used
                   |should be more useful       |variables used only as
                   |                            |lvalue


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


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

* [Bug c/36390] do not mark as used variables used only as lvalue
  2008-05-30 13:17 [Bug c/36390] New: Unused variable warning should be more useful jmfo1982 at yahoo dot es
  2008-08-14 23:33 ` [Bug c/36390] " eugene dot zelenko at gmail dot com
  2009-02-12 14:33 ` [Bug c/36390] do not mark as used variables used only as lvalue manu at gcc dot gnu dot org
@ 2009-11-24  8:10 ` jakub at gcc dot gnu dot org
  2009-11-24 11:37 ` jakub at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-11-24  8:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jakub at gcc dot gnu dot org  2009-11-24 08:10 -------
-Wunused-variable is checking the TREE_USED flag, which is set quite early
during the parsing (in C FE build_external_ref, in C++ FE mark_used called from
finish_id_expression).  At that point the parser doesn't track whether it is
LHS of an assignment or RHS in a way that could be easily checked in those
routines unfortunately (and just setting a some parser flag e.g. around
lhs = c_parser_conditional_expression (parser, after);
in c_parser_expr_no_commas is insufficient, we want that only for the actual
LHS, but not other variables referenced in that, say in x[i] = 5; i must be
marked as used, etc.).  So implementing this isn't just a one-liner.

On the other side, I agree the warning is very useful in some cases, not so
much when var is only used on LHS where RHS has no side-effects, that is just
optimized out, but if an otherwise unused variable is initialized using some
expensive function call the user might find out that the call is just a waste
of time and remove it, even when it is not marked pure/const and thus the
compiler can't optimize it itself.


-- 


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


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

* [Bug c/36390] do not mark as used variables used only as lvalue
  2008-05-30 13:17 [Bug c/36390] New: Unused variable warning should be more useful jmfo1982 at yahoo dot es
                   ` (2 preceding siblings ...)
  2009-11-24  8:10 ` jakub at gcc dot gnu dot org
@ 2009-11-24 11:37 ` jakub at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-11-24 11:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jakub at gcc dot gnu dot org  2009-11-24 11:36 -------


*** This bug has been marked as a duplicate of 18624 ***


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


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


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

end of thread, other threads:[~2009-11-24 11:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-30 13:17 [Bug c/36390] New: Unused variable warning should be more useful jmfo1982 at yahoo dot es
2008-08-14 23:33 ` [Bug c/36390] " eugene dot zelenko at gmail dot com
2009-02-12 14:33 ` [Bug c/36390] do not mark as used variables used only as lvalue manu at gcc dot gnu dot org
2009-11-24  8:10 ` jakub at gcc dot gnu dot org
2009-11-24 11:37 ` jakub at gcc dot gnu dot 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).