[PATCH] D37014: [clang-tidy] Add a checker to remove useless intermediate variables before return statements with comparisons
Tristan Bourvon via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 22 08:46:32 PDT 2017
tbourvon created this revision.
Herald added subscribers: xazax.hun, JDevlieghere, mgorny.
This patch adds a checker to detect patterns of the following form:
auto IntermediateVar = foo();
return (IntermediateVar == 1);
and suggests to turn them into:
return (foo() == 1);
The reasoning behind this checker is that this kind of pattern is useless and lowers readability as long as the return statement remains rather short.
The idea of this checker was suggested to me by Sylvestre Ledru.
https://reviews.llvm.org/D37014
Files:
clang-tidy/readability/CMakeLists.txt
clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tidy/readability/UselessIntermediateVarCheck.cpp
clang-tidy/readability/UselessIntermediateVarCheck.h
clang-tidy/utils/LexerUtils.cpp
clang-tidy/utils/LexerUtils.h
clang-tidy/utils/Matchers.h
docs/ReleaseNotes.rst
docs/clang-tidy/checks/list.rst
docs/clang-tidy/checks/readability-useless-intermediate-var.rst
test/clang-tidy/readability-useless-intermediate-var.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37014.112179.patch
Type: text/x-patch
Size: 33186 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170822/b6f724d6/attachment-0001.bin>
More information about the cfe-commits
mailing list