[PATCH] 'size' call that could be replaced with 'empty' on STL containers
Gábor Horváth
xazax.hun at gmail.com
Mon Jan 12 05:15:39 PST 2015
Hi klimek, alexfh,
We are porting some of the checkers at a company we developed to the Clang Tidy infrastructure. We would like to open source the checkers that may be useful for the community as well. This patch is the first checker that is being ported to Clang Tidy. We also added fix-it hints, and applied them to LLVM: http://reviews.llvm.org/D6924
The code compiled and the unit tests are passed after the fixits was applied.
The documentation of the checker:
/// The emptiness of a container should be checked using the empty method
/// instead of the size method. It is not guaranteed that size is a
/// constant-time function, and it is generally more efficient and also shows
/// clearer intent to use empty. Furthermore some containers may implement the
/// empty method but not implement the size method. Using empty whenever
/// possible makes it easier to switch to another container in the future.
It also uses some custom ASTMatchers. In case you find them useful I can submit them as separate patches to clang. I will apply your suggestions to this patch.
http://reviews.llvm.org/D6925
Files:
clang-tidy/readability/CMakeLists.txt
clang-tidy/readability/ContainerSizeEmpty.cpp
clang-tidy/readability/ContainerSizeEmpty.h
clang-tidy/readability/ReadabilityTidyModule.cpp
modularize/ModuleAssistant.cpp
module-map-checker/ModuleMapChecker.cpp
test/clang-tidy/readibility-container-size-empty.cpp
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6925.18016.patch
Type: text/x-patch
Size: 13922 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150112/ecd58662/attachment.bin>
More information about the cfe-commits
mailing list