Clean up compiler warnings (Mark unused variables with '[[maybe_unused]]') #2132
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As part of #2006, warnings generated by -Wall and -Wextra will need to be fixed. The tallest nail gets the hammer, I see at least 90 'unused-parameter' warnings on MacOS with the default build options.
Here I make a minimal pull request fixing one file to make discussion easy:
I see the minimum C++ standard is C++11, I thought this would preclude some more modern features, but compilers seem to support some
I see two ways of fixing this warning (that don't change the inputs to the function):
Option 1: Use [[maybe_unused]]
This is a 'modern' feature, while officially a C++17 feature, my tests show most compilers seem to understand it (even when set to C++11)
https://godbolt.org/z/qdPvo6Mdc
Testing shows that the minimum compiler version (that build this test function in C++11)
gcc 7.1
clang 3.9.0
msvc v19.21 VS16.1*
*msvc throws a warning that
[[maybe_unused]]
is ignoredI am very interested to see if your CI actions are happy with this syntax.
Optional 2: Comment out the variable name
This is perhaps a more old fashioned fix, the major disadvantage is that
/* */
doesn't nest. So it becomes annoying to comment out an entire function.I look forward to hearing your thoughts