Hello All: I found an issue about g++, it is OK for "-Wall -O0", but will report -Wunused-variable for "-Wall -O1|2|3|s". The original version (e.g. gcc 4.8.3 redhat version) does not report warning for "-Wall -O?".
The related operation: [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 g++ information: [root@localhost qemu_cc]# /usr/local/bin/g++ -v Using built-in specs. COLLECT_GCC=/usr/local/bin/g++ COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc/configure --disable-multilibs --disable-nls Thread model: posix gcc version 5.0.0 20141003 (experimental) (GCC) If we are sure it is a bug, I shall try to analyze it within this month. Thanks -- Chen Gang Open, share, and attitude like air, water, and life which God blessed