public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/44062]  New: (void)var; doesn't prevent 'set but not used' warning
@ 2010-05-10 15:05 jeffrey dot donner at gmail dot com
  2010-05-10 15:48 ` [Bug c++/44062] " jakub at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: jeffrey dot donner at gmail dot com @ 2010-05-10 15:05 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1055 bytes --]

Doing

  (void)var;

does not 'use' the var, eg: 

  void f()
  {
     int i = 6; // or a fn call whose return value you don't care about
     (void)i;
  }

jd@shade:~$ g++ -Wall -Wextra unused.cpp
unused.cpp: In function ‘void f()’:
unused.cpp:3:8: warning: variable ‘i’ set but not used
[-Wunused-but-set-variable]

Doing this (void)var; trick is a long-standing way to quiet 'unused' warnings -
eg in g++ 4.4.3 there is no warning. 

Version used:

jd@shade:~$ g++ --version
g++ (GCC) 4.6.0 20100508 (experimental)


-- 
           Summary: (void)var; doesn't prevent 'set but not used' warning
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jeffrey dot donner at gmail dot com
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


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


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

* [Bug c++/44062] (void)var; doesn't prevent 'set but not used' warning
  2010-05-10 15:05 [Bug c++/44062] New: (void)var; doesn't prevent 'set but not used' warning jeffrey dot donner at gmail dot com
@ 2010-05-10 15:48 ` jakub at gcc dot gnu dot org
  2010-05-10 15:51 ` jakub at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-05-10 15:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from jakub at gcc dot gnu dot org  2010-05-10 15:48 -------
Oops, seems something I should have covered in the testsuite.  For C it works
correctly.


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu dot
                   |                            |org, dodji at gcc dot gnu
                   |                            |dot org


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


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

* [Bug c++/44062] (void)var; doesn't prevent 'set but not used' warning
  2010-05-10 15:05 [Bug c++/44062] New: (void)var; doesn't prevent 'set but not used' warning jeffrey dot donner at gmail dot com
  2010-05-10 15:48 ` [Bug c++/44062] " jakub at gcc dot gnu dot org
@ 2010-05-10 15:51 ` jakub at gcc dot gnu dot org
  2010-05-10 16:51 ` jakub at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-05-10 15:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from jakub at gcc dot gnu dot org  2010-05-10 15:51 -------
Created an attachment (id=20620)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20620&action=view)
testcases

2 new testcases


-- 


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


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

* [Bug c++/44062] (void)var; doesn't prevent 'set but not used' warning
  2010-05-10 15:05 [Bug c++/44062] New: (void)var; doesn't prevent 'set but not used' warning jeffrey dot donner at gmail dot com
  2010-05-10 15:48 ` [Bug c++/44062] " jakub at gcc dot gnu dot org
  2010-05-10 15:51 ` jakub at gcc dot gnu dot org
@ 2010-05-10 16:51 ` jakub at gcc dot gnu dot org
  2010-05-11 12:49 ` jakub at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-05-10 16:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jakub at gcc dot gnu dot org  2010-05-10 16:50 -------
Created an attachment (id=20622)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20622&action=view)
gcc46-pr44062.patch

Actually, I've found 2 issues even in the C FE related to comma expressions
with
LHS or RHS without side-effects.
The C++ FE changes needed for these new testcases are missing though.


-- 


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


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

* [Bug c++/44062] (void)var; doesn't prevent 'set but not used' warning
  2010-05-10 15:05 [Bug c++/44062] New: (void)var; doesn't prevent 'set but not used' warning jeffrey dot donner at gmail dot com
                   ` (2 preceding siblings ...)
  2010-05-10 16:51 ` jakub at gcc dot gnu dot org
@ 2010-05-11 12:49 ` jakub at gcc dot gnu dot org
  2010-05-11 18:13 ` jakub at gcc dot gnu dot org
  2010-05-11 18:29 ` jakub at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-05-11 12:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jakub at gcc dot gnu dot org  2010-05-11 12:48 -------
Created an attachment (id=20628)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20628&action=view)
gcc46-pr44062-c++.patch

C++ change that fixes this.
It treats all (void) / static_cast <void> conversions and the implicit
conversion thereof on lhs of compound expr as when a decl etc. is appearing
alone in a statement, with the difference that for say
(a, b++, c = d);
we don't mark c DECL_READ_P - mark_exp_read normally handles MODIFY_EXPR for
cases like z = (c = d); where we want to set DECL_READ_P on c.  But in this
case of a cast to void/decl/handled component alone in a stmt or comma
expression lhs, we want to mark everything but MODIFY_EXPR.


-- 


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


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

* [Bug c++/44062] (void)var; doesn't prevent 'set but not used' warning
  2010-05-10 15:05 [Bug c++/44062] New: (void)var; doesn't prevent 'set but not used' warning jeffrey dot donner at gmail dot com
                   ` (3 preceding siblings ...)
  2010-05-11 12:49 ` jakub at gcc dot gnu dot org
@ 2010-05-11 18:13 ` jakub at gcc dot gnu dot org
  2010-05-11 18:29 ` jakub at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-05-11 18:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jakub at gcc dot gnu dot org  2010-05-11 18:12 -------
Subject: Bug 44062

Author: jakub
Date: Tue May 11 18:12:28 2010
New Revision: 159286

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159286
Log:
        PR c++/44062
        * c-parser.c (c_parser_expression): Mark LHS of a comma
        expression as read if it is a decl, handled component or
        COMPOUND_EXPR with that on the RHS.
        * c-typeck.c (c_process_expr_stmt): Mark RHS of COMPOUND_EXPR
        if it is a decl or handled component.

        * semantics.c (finish_expr_stmt): Don't call mark_exp_read here...
        * cvt.c (convert_to_void): ... but here.  If expr is a COMPOUND_EXPR,
        look at its second operand.

        * c-c++-common/Wunused-var-7.c: New test.
        * g++.dg/warn/Wunused-var-9.C: New test.

Added:
    trunk/gcc/testsuite/c-c++-common/Wunused-var-7.c
    trunk/gcc/testsuite/g++.dg/warn/Wunused-var-9.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-parser.c
    trunk/gcc/c-typeck.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cvt.c
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug c++/44062] (void)var; doesn't prevent 'set but not used' warning
  2010-05-10 15:05 [Bug c++/44062] New: (void)var; doesn't prevent 'set but not used' warning jeffrey dot donner at gmail dot com
                   ` (4 preceding siblings ...)
  2010-05-11 18:13 ` jakub at gcc dot gnu dot org
@ 2010-05-11 18:29 ` jakub at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-05-11 18:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jakub at gcc dot gnu dot org  2010-05-11 18:29 -------
Fixed.


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.6.0


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


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

end of thread, other threads:[~2010-05-11 18:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-10 15:05 [Bug c++/44062] New: (void)var; doesn't prevent 'set but not used' warning jeffrey dot donner at gmail dot com
2010-05-10 15:48 ` [Bug c++/44062] " jakub at gcc dot gnu dot org
2010-05-10 15:51 ` jakub at gcc dot gnu dot org
2010-05-10 16:51 ` jakub at gcc dot gnu dot org
2010-05-11 12:49 ` jakub at gcc dot gnu dot org
2010-05-11 18:13 ` jakub at gcc dot gnu dot org
2010-05-11 18:29 ` 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).