http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55643
Bug #: 55643 Summary: g++ 4.7 gives "warning: variable ‘myVar’ set but not used [-Wunused-but-set-variable]" when an "enum class"-typed variable is cast to double before use Classification: Unclassified Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: dholb...@cs.stanford.edu When I compile the attached C++ source file with g++ 4.7.2, I get this build warning: > gcc-warning-test.cpp: In function ‘int main()’: > gcc-warning-test.cpp:19:10: warning: variable ‘myVar’ set but > not used [-Wunused-but-set-variable] I believe this is incorrect, because I _am_ using the variable -- I'm printing out its value like so: > printf("%f\n", (double)myVar); If I instead cast it to an int or an unsigned value, I get no warning -- that apparently counts as "using" it, from GCC's perspective. But when I use (float)myVar or (double)myVar, GCC apparently doesn't count that as "using". NOTE: This only happens with "enum class" (a C++11 feature). If I instead just use "enum", then I don't get a warning. For comparison, clang yields expected results. (No warning -- and it does warn if I remove the printf statements, indicating that it is doing some checking) SYSTEM INFO: g++-4.7.real (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2 OS: Ubuntu 12.10 Kernel: Linux 3.5.0-19-generic x86_64