Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[-Wunused-parameter]

25 views
Skip to first unread message

AL.GleeD NICE

unread,
Dec 25, 2018, 9:47:52 PM12/25/18
to
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


--------
I do not know the direct cause. And the associated curve

Ian Collins

unread,
Dec 25, 2018, 9:53:42 PM12/25/18
to
The named parameter, o, is unused. Drop the name.

void on_large_pages(const Option&) { TT.resize(0); }

--
Ian.

Alf P. Steinbach

unread,
Dec 25, 2018, 10:31:32 PM12/25/18
to
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


ViralTaco

unread,
Dec 26, 2018, 3:07:51 PM12/26/18
to
Hey,
Like Alf mentioned I suggest using the attribute `[[maybe_unused]]`
Note that `[[unused]]` may also exist but isn't standard in C++17 as far as I know. (And won't work on the latest version of msvc I tried)…
ie:
void foo([[maybe_unused]] const Option& o) /* const noexcept(true) */ {
// function body;
}

AL.GleeD NICE

unread,
Dec 30, 2018, 4:13:01 AM12/30/18
to
------------


welcome everybody
All these attempts did not succeed

I suspect the translator has an incomprehensible side of the parameter

Thank you all for your attempts
0 new messages