On Mon, Oct 13, 2014 at 09:10:31PM +0800, Chen Gang wrote: > Oh, yes. Originally I got this warning by compiling Qemu. And sorry for > my sample (test.cc) may be not quite precise. > > For me, I guess: > > - If the constant number is defined in the header file, and never be > used, our g++ need not report warning about [-Wunused-variable].
That is nonsense, even if you define such a "constant" in a header file, it still means runtime overhead (the variable needs to be constructed at runtime, const is not the same thing as constexpr). So, IMHO the warning is desirable even if it is in headers, it is something you should reconsider. Making the function constexpr makes the warning of course go away, then there is no runtime overhead associated with it; but you'll need C++11 for that. Jakub