Discussion:
[Consult] g++: About "-Wunused-variable" for constant variable in header file
Chen Gang
2014-10-14 21:57:00 UTC
Permalink
Hello All:

At present, I met one warning issue about gcc 5.0.0.

- For "const float a = 3.4 - 2.1 / 3;", if it is unused, gcc5 will not
report warning.

- "const char n() {return 1;}; const a = n();", if 'a' is unused, gcc5
will report warning.

For gcc old version (e.g. gcc4), it will not report warning. Is it the
new feature for gcc5, or just a gcc5's bug?

Welcome any ideas, suggestions or completions.

Thanks.
--
Chen Gang

Open share and attitude like air water and life which God blessed
Jonathan Wakely
2014-10-15 09:18:44 UTC
Permalink
Post by Chen Gang
At present, I met one warning issue about gcc 5.0.0.
- For "const float a = 3.4 - 2.1 / 3;", if it is unused, gcc5 will not
report warning.
Because there is no cost to initializing the variable.
Post by Chen Gang
- "const char n() {return 1;}; const a = n();", if 'a' is unused, gcc5
will report warning.
Because it requires dynamic initialization, running a function at
startup, which has a cost. If you don't use the variable then you
might not want to run the initialization code at startup, so you get a
warning.
Post by Chen Gang
For gcc old version (e.g. gcc4), it will not report warning. Is it the
new feature for gcc5, or just a gcc5's bug?
I think this behaviour is intended and is not a bug.
Chen Gang
2014-10-15 09:35:32 UTC
Permalink
Post by Jonathan Wakely
Post by Chen Gang
At present, I met one warning issue about gcc 5.0.0.
- For "const float a = 3.4 - 2.1 / 3;", if it is unused, gcc5 will not
report warning.
Because there is no cost to initializing the variable.
Post by Chen Gang
- "const char n() {return 1;}; const a = n();", if 'a' is unused, gcc5
will report warning.
Because it requires dynamic initialization, running a function at
startup, which has a cost. If you don't use the variable then you
might not want to run the initialization code at startup, so you get a
warning.
Post by Chen Gang
For gcc old version (e.g. gcc4), it will not report warning. Is it the
new feature for gcc5, or just a gcc5's bug?
I think this behaviour is intended and is not a bug.
Thank you very much four your details reply! And thank Jakub Jelinek for
the almost same reply in another original mailing thread, too.

I shall forward your reply to the other related mail thread which is
related with QEMU.

Thanks again. :-)
--
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
Loading...