storm
storm copied to clipboard
Silence unused parameter warnings
There are several unused parameter warnings all over the place.
As these parameters mostly exist on purpose (e.g. for function overloading), those warnings can probably be ignored.
Once we are at c++17, we should insert the new attribute [[maybe_unused]]
wherever this is the case.
In inheritance situations, do we want the [[maybe_unused]]
only in the classes where the parameter is not used or in all sub-/super-classes with the function? Also, in the .cpp files or the corresponding .h files or both?
In inheritance situations, do we want the
[[maybe_unused]]
only in the classes where the parameter is not used or in all sub-/super-classes with the function? Also, in the .cpp files or the corresponding .h files or both?
I'd say only in places where a warning is issued and preferably where the function is defined, i.e. in .cpp
files.
If a parameter is marked as unused but is actually used but within a #ifdef STORM_HAVE_SPOT
block (or similar #ifdef
blocks), do we want to suppress the warnings there as well?
Preferably yes, because it is easier to enforce that we have no warnings if we really do not have warnings :-). You can do this with a #else
I don't think you need an #else
block for this. You can just use [[maybe_unused]]
there, even if the thing is actually used sometimes. Actually, this is one of the intended use cases of that attribute (thus its called maybe_unused
and not just unused
)
Yeah, I think I'll use the [[maybe_unused]]
as the #ifdef
is inside the function. Thanks!
I noticed that for functions that need to have a certain signature, (e.g. for overrides of virtual functions) but which we don't use, it's possible to just not give the parameters names, i.e. just put the data type into the signature. In that case it also generates no unused parameter warnings. Is that something that might be worth using? Maybe it'd look "cleaner" to do that for unused parameters that need to be in the signature for such reasons and use the [[maybe_unused]]
for things like the ifdef
blocks?
I'd have to redo quite a bunch of stuff but I kept a markdown document of what I changed and I don't mind, it just might take some extra time. Jip suggested I bring it up here, so I'm doing that now before I continue so that it doesn't have to be redone entirely later.
As far as I know, there are three ways to deal with this:
- Omit the parameter name entirely:
void f(int)
- Comment out the parameter name:
void f(int /*x*/)
- Use the attribute:
void f([[maybe_unused]] int x)
Personally, I prefer to keep the names of the parameters in some way. And I like consistency. ~Since commenting out is not always an option (e.g. the #ifdef
thing discussed above), this leaves us with the last option.~
~Again, this is my personal opinion on this. I'm happy to hear other opinions.~
I don't mind either way, I'd just been wondering and thought I'd ask just in case it wasn't considered before or anything because I noticed a few unnamed parameters and saw that they didn't produce the warnings unlike named parameters in the same function.
I'll continue with the [[maybe_unused]]
for now, but if anything changes just let me know and I can adjust it accordingly :)