This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix modernize-use-nodiscard check for classes marked as [[nodiscard]]
ClosedPublic

Authored by sedykh.eugene on Oct 24 2019, 8:35 AM.
Tokens
"Like" token, awarded by MyDeveloperDay.

Details

Summary

Current implementation suggests to add [[nodiscard]] to methods even if the return type is marked already as [[nodiscard]]:

Try this:

struct [[nodiscard]] S{};

class C{
  S method() const; --> suggests adding [[nodiscard]]
};

This small diff fixes this incorrect behaviour.

This is my first timid try to contribute to open source, so please help me with this piece of code. Maybe there are better ways.

Diff Detail

Event Timeline

sedykh.eugene created this revision.Oct 24 2019, 8:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 24 2019, 8:35 AM
sedykh.eugene edited the summary of this revision. (Show Details)Oct 24 2019, 8:39 AM

Thank you for the patch, I wrote this checker originally and this LGTM.

I'm not sure if others have any objections to using "using clang::attr::WarnUnusedResult" in the body of the function, I couldn't see this pattern used elsewhere in clang-tidy, all I've seen is it being used in ClangTidyOptions.cpp globally.

I'd wait for some more feedback from the main owners, but thank you and welcome.

aaron.ballman accepted this revision.Oct 28 2019, 8:57 AM

Thank you for the patch, and welcome! LGTM aside from a minor nit. Do you need someone to commit this on your behalf?

clang-tidy/modernize/UseNodiscardCheck.cpp
97

I'd just sink this down into the matcher itself rather than use a using declaration for it.

This revision is now accepted and ready to land.Oct 28 2019, 8:57 AM

I removed using. Not a big deal. Thank you for the reviews!

Thank you for the patch, and welcome! LGTM aside from a minor nit. Do you need someone to commit this on your behalf?

Thank you. You mean I don't rights? Then, yes, I need someone to commit.

Thank you for the patch, I've commit on your behalf in 661d2ce619e05dc47a9a232333c01dcba445cd13