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;
}
j...@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:
j...@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