-
Notifications
You must be signed in to change notification settings - Fork 2.3k
enh(all): Add [[nodiscard]] and [[maybe_unused]] attributes
#5156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
c5add77 to
6f042a9
Compare
|
|
7dbfa1f to
d77d238
Compare
|
Would it be possible to get this merged before the 1.15 release? I understand if not, but it is nearly done. I have covered all methods across the project. |
479e634 to
6f154e8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
It is quite a big change. I'll need some time for review. |
[[nodiscard]] and [[maybe_unused]] attributes
|
There are lots of changes. Instead of adding comments to the source code I provide some general observations. |
|
[[nodiscard]] on Enum Types This is unusual and mostly useless. [[nodiscard]] on an enum means functions returning that enum type should have their return value checked. But enum values are typically used as parameters, not return values. The attribute on the enum declaration itself doesn't do anything for enum values. |
|
[[nodiscard]] on Internal/Helper Classes These are internal classes that users don't directly construct or receive from functions. Adding [[nodiscard]] adds noise without benefit. |
|
[[nodiscard]] on Dereference Operators This is wrong. These operators are used for accessing members: The -> operator result IS used implicitly. This will likely cause spurious warnings. |
|
[[nodiscard]] on Nullable and Optional Classes Reconsider this. While it ensures you use the object, these types are commonly constructed just to be assigned to variables or passed around. The standard library's std::optional is not marked nodiscard. |
|
I decided to put nodiscard on enums and class internal types because I wanted to ensure that data like this is not discarded. I have gone ahead and applied your requested changes, nonetheless. |
|
@mikomikotaishi , you don't have to force push. It is harder to track changes between the commits when force pushed. |
|
Noted |
Not sure what you mean by this, but |
|
Is there anything else I should address in this PR, pending reviews from the other reviewers? |
|
Build with enabled compiler warnings shall be inspected whether introduction of attributes introduced new warnings and then decide how to fix those warnings:
Two jobs with enabled warnings are built on github: macos-clang-cmake-warnings and macos-msvc-cmake-warnings. |
|
Apologies, accidentally force-pushed instead of creating a new commit. (I'll force-push when making amendments from now on and use proper commits when adding something new.) Anyway, I think I've done what I can to remove the warnings we were getting. |
f558a6f to
993c2ff
Compare
|
Never mind, I see the problem now, I accidentally overwrote the |
|
@matejk Is there anything to do next? |
Addresses part of #5152. This PR adds
[[nodiscard]]attributes to many methods and types that would otherwise be important not to discard.Unlike
POCO_DEPRECATED()which can be disabled, I am not going to put[[nodiscard]]behind a macro as using deprecated symbols is intended while discarding a value is certainly a programming error.