31.12.2022 17:05 Juha Nieminen kirjutas:
> Paavo Helde <
ees...@osa.pri.ee> wrote:
>> Sure, these are probably specific to our codebase:
>>
>> -Wno-missing-field-initializers -Wno-unused-parameter
>> -Wno-unused-local-typedefs -Wno-deprecated-declarations -Wno-parentheses
>>
>> The first one is there probably because we have many classes whose
>> members are often not initialized by the constructions, but later, by
>> the framework.
>
> I think that using [[maybe_unused]] is better than disabling the warning
> because it more explicitly indicates that it being unused is not a mistake
> and the programmer was aware of it.
You are right in that the unused parameter warnings should be dealt
case-by-case instead of a global compiler option. I guess there was no
time or willingness to do that when the compiler suddenly started to
spit out hundreds of such warnings, and after adding the global option
there has been no motivation to do that.
Still, I'm not convinced [[maybe_unused]] is the best solution always.
As far as I can see, this is meant more for conditional compilation,
where a thing might be indeed sometimes used and sometimes not,
depending on preprocessor macro definitions.
In my code, I get this warning mainly for virtual function overrides
where some parameter is e.g. only used by 1 override of 10. And in those
9 other overrides the parameter is not maybe unused, but definitely
unused. Alas, by some reason there is no [[unused]] attribute.
In this scenario, I believe it might be better (i.e. more readable) to
just delete or comment out the parameter name, it will have the same
effect.