This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [Consult] g++: About "-Wunused-variable" for constant variable initialized by function
- From: Chen Gang <gang dot chen dot 5i5j at gmail dot com>
- To: Jason Merrill <jason at redhat dot com>, Jeff Law <law at redhat dot com>, nathan at codesourcery dot com
- Cc: gcc at gcc dot gnu dot org, Peter Maydell <peter dot maydell at linaro dot org>
- Date: Mon, 13 Oct 2014 21:18:26 +0800
- Subject: Re: [Consult] g++: About "-Wunused-variable" for constant variable initialized by function
- Authentication-results: sourceware.org; auth=none
- References: <543A910F dot 7060301 at gmail dot com> <543BAF23 dot 6080808 at redhat dot com>
On 10/13/14 18:53, Jason Merrill wrote:
> 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/
>
OK, thanks. After finish this consult, I shall report bugs, and shall
try to fix it (I got it from Qemu which in my current focus border).
Hope I can finish within this month.
And one another consult: if the constant variable is defined in header
file, and never be used, need our g++ still report warning about
[-Wunused-variable] too (for me, I guess, not)?
Thanks.
--
Chen Gang
Open, share, and attitude like air, water, and life which God blessed