llvm-project/clang-tools-extra/clang-tidy/readability
Alexander Kornienko 4babd689f9 clang-tidy: 'size' call that could be replaced with 'empty' on STL containers
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

Patch by Gábor Horváth!

llvm-svn: 226172
2015-01-15 15:46:58 +00:00
..
BracesAroundStatementsCheck.cpp
BracesAroundStatementsCheck.h
CMakeLists.txt clang-tidy: 'size' call that could be replaced with 'empty' on STL containers 2015-01-15 15:46:58 +00:00
ContainerSizeEmpty.cpp clang-tidy: 'size' call that could be replaced with 'empty' on STL containers 2015-01-15 15:46:58 +00:00
ContainerSizeEmpty.h clang-tidy: 'size' call that could be replaced with 'empty' on STL containers 2015-01-15 15:46:58 +00:00
ElseAfterReturnCheck.cpp clang-tidy: Add initial check for "Don't use else after return". 2015-01-14 19:37:54 +00:00
ElseAfterReturnCheck.h clang-tidy: Add initial check for "Don't use else after return". 2015-01-14 19:37:54 +00:00
FunctionSize.cpp
FunctionSize.h
Makefile
NamespaceCommentCheck.cpp [clang-tidy] Move the missing namespace comment warnings to the closing brace 2014-11-17 17:32:32 +00:00
NamespaceCommentCheck.h
ReadabilityTidyModule.cpp clang-tidy: 'size' call that could be replaced with 'empty' on STL containers 2015-01-15 15:46:58 +00:00
RedundantSmartptrGet.cpp
RedundantSmartptrGet.h