- this adds a new check: readability-return-with-redundant-parens
We can find these with the AST matcher. We exclude macros.
Paths
| Differential D131985
clang-tidy: strip useless parens from `return` statements Needs ReviewPublic Authored by oleg.smolsky on Aug 16 2022, 11:20 AM.
Details Summary
We can find these with the AST matcher. We exclude macros.
Diff Detail Event TimelineComment Actions The idea of this check is good, but restricting it to only return statements seems baffling. A general check that could remove useless parens would have a lot more value.
Comment Actions
Of course a more general check would be more generally useful. Yet that requires a lot more code as handling many more contexts is involved in C++. Basically this change addresses a concrete, somewhat wide-spread silly habit that exists in the wild. Comment Actions
I recently observed in the wild patterns like: std::vector<std::string> data; for (std::vector<std::string>::iterator it = data.begin(); it != data.end(); ++it) std::cout << (*it) << std::endl; Comment Actions
While I have not seen that one, I've seen something similar, with even more involved syntax: for (auto it = data.begin(); it != data.end(); ++it) std::cout << (*it).something << std::endl; people write wild syntax... Comment Actions Simplify and generalize the AST matcher. We just want to find all return statements in function definitions.
Revision Contents
Diff 453740 clang-tools-extra/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.h
clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst
clang-tools-extra/docs/clang-tidy/checks/readability/return-with-redundant-parens.rst
clang-tools-extra/test/clang-tidy/readability-return-with-redundant-parens.cpp
|
Please use double back-ticks for language constructs.