[Consult] g++: About "-Wunused-variable" for constant variable initialized by function

Jason Merrill jason@redhat.com
Mon Oct 13 10:53:00 GMT 2014


On 10/12/2014 10:32 AM, Chen Gang wrote:
>    [root@localhost qemu_cc]# cat test.cc
>    const char n() { return 1; }
>    const char c =  n();
>    [root@localhost qemu_cc]# /usr/local/bin/g++ -Wall -O0 -c -o test.o test.cc
>    [root@localhost qemu_cc]# /usr/local/bin/g++ -Wall -O2 -c -o test.o test.cc
>    test.cc:2:12: warning: 'c' defined but not used [-Wunused-variable]
>     const char c =  n();
>                ^

The warning is correct (and new).  Please submit bug reports via the 
website; see https://gcc.gnu.org/bugs/

Jason




More information about the Gcc mailing list