public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55643] New: 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
@ 2012-12-10 20:40 dholbert at cs dot stanford.edu
  2012-12-10 20:41 ` [Bug c++/55643] " dholbert at cs dot stanford.edu
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: dholbert at cs dot stanford.edu @ 2012-12-10 20:40 UTC (permalink / raw)
  To: gcc-bugs


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: unassigned@gcc.gnu.org
        ReportedBy: dholbert@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


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

end of thread, other threads:[~2012-12-11 19:20 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-10 20:40 [Bug c++/55643] New: 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 dholbert at cs dot stanford.edu
2012-12-10 20:41 ` [Bug c++/55643] " dholbert at cs dot stanford.edu
2012-12-10 20:42 ` dholbert at cs dot stanford.edu
2012-12-10 20:44 ` dholbert at cs dot stanford.edu
2012-12-10 21:17 ` [Bug c++/55643] [4.7/4.8 Regression] g++ incorrectly prints " jakub at gcc dot gnu.org
2012-12-10 23:54 ` [Bug c++/55643] [4.7/4.8 Regression] [C++11] incorrect "warning: variable ‘myVar’ set but not used" with an "enum class"-typed variable is casted to double for the use pinskia at gcc dot gnu.org
2012-12-11  8:07 ` jakub at gcc dot gnu.org
2012-12-11 19:02 ` jakub at gcc dot gnu.org
2012-12-11 19:06 ` jakub at gcc dot gnu.org
2012-12-11 19:08 ` jakub at gcc dot gnu.org
2012-12-11 19:20 ` dholbert at cs dot stanford.edu

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).