Use [[nodiscard]] in more places
#3137
Merged
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.
Description
This PR does two things. Primarily it adds
[[nodiscard]]to many APIs (both public and private) where it would be unambiguously incorrect to ignore the return value. This makes it more difficult to write programs that misuse the API. GCC and Clang will warn about this by default so it's safe to assume once we add this all SFML 3 users will start potentially receiving these warnings. Whether or not those warnings are converted into errors is a matter of user preference. There are likely more APIs where[[nodiscard]]would be appropriate so we may add it in more places after this PR once a precedent has been established.The second thing this PR does is use clang-tidy's
modernize-use-nodiscardcheck to automatically flag APIs that ought to be marked with[[nodiscard]]but are not. This only applies to class member functions so this check will not touch free functions. We will have to manually audit the codebase to find free functions that need the[[nodiscard]]attribute. This is doable albeit rather labor intensive.