On 26.12.2018 03:47, AL.GleeD NICE wrote:
> ucioption.cpp:42:35: warning: unused parameter 'o' [-Wunused-parameter]
> void on_large_pages(const Option& o) { TT.resize(0); } // warning is ok, will be removed
You get the warning because `o` is not used.
The traditional solution has been to either drop the argument name,
void on_large_pages( const Option& )
... or to pseudo-use it in an expression casted to `void`:
void on_large_pages( const Option& o )
{
(void) o;
// more code
}
To be sure that that doesn't dis-inform a reader after some maintainer
has introduced some actual use of `o`, you can inhibit further use by
shadowing the name, e.g.
void on_large_pages( const Option& o )
{
(void) o; struct o;
// more code, that just can't access `o`
}
There are two main problems with that, though: (A) some programmers may
not understand what the heck that's about, even if you encapsulate it in
a macro with self-describing name, and (B) the compiler's diagnostics
when some maintainer inadvertently uses `o` with removing that line, and
be pretty ungrokable and misleading.
---
C++17 introduced an attribute for this,
void on_large_pages( [[maybe_unused]] const Option& o )
And I think it was from C++14 there is something like dummy assign in
the standard library, but I'm unable to find it now. I just noted it
when I saw it, once, that hey that's cool, I'll start using that. And
then I forgot all about it.
Cheers!,
- Alf