enh(all): Add [[nodiscard]] and [[maybe_unused]] attributes#5156
enh(all): Add [[nodiscard]] and [[maybe_unused]] attributes#5156mikomikotaishi wants to merge 1 commit intopocoproject:mainfrom
[[nodiscard]] and [[maybe_unused]] attributes#5156Conversation
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.
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. |
993c2ff to
79b5c6f
Compare
|
Never mind, I see the problem now, I accidentally overwrote the |
|
@matejk Is there anything to do next? |
|
I am quite busy with other projects currently. I'll take a look ASAP. Thank you so much for your contribution so far. |
|
Hi @matejk, is there still any time to eventually review and merge this? |
|
Hi, sorry for not answering. We are preparing release 1.15.0. Changes in this PR will be included in the next release. Thank you for your patience. |
|
So would it be possible to roll out this in a minor release (like 1.15.1)? |
|
Now that 1.15.0 is rolled out, could we look towards integrating this for 1.15.1 perhaps? |
|
@matejk also I think the website needs to be updated for 1.15.0, it still says 1.14.2 |
|
I'd also like to ask here (before making an issue that might just be not worth investigating): is there any reason why we primarily use unscoped C-style |
The reason is very simple: lots of Poco code was written before C++11 standard. Probably some of the enums could be converted to enum class. Probably not all. |
We'll include into 1.16.0 with the next round of C++ modernisation. |
As a user of Poco and one who has done these types of changes, I'd suggest a middle ground approach. It's more forgiving on user code to use |
Could this still be merged for the time being or will we have to wait until work on 1.16.0 begins before merging this into the library?
I agree, I think the primary goal of moving towards |
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.