llvm-project/clang-tools-extra/clang-tidy
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
..
google [cleanup] Re-sort the #include lines with llvm/utils/sort_includes.py 2015-01-14 11:24:38 +00:00
llvm [cleanup] Re-sort the #include lines with llvm/utils/sort_includes.py 2015-01-14 11:24:38 +00:00
misc [cleanup] Re-sort the #include lines with llvm/utils/sort_includes.py 2015-01-14 11:24:38 +00:00
readability clang-tidy: 'size' call that could be replaced with 'empty' on STL containers 2015-01-15 15:46:58 +00:00
tool [clang-tidy] Fix a typo. 2014-12-09 15:02:17 +00:00
utils Fix llvm-header-guard check. 2014-10-15 12:18:35 +00:00
CMakeLists.txt [CMake] Add dependencies on clangToolingCore. 2014-10-30 00:44:01 +00:00
ClangTidy.cpp Add flag --enable-check-profile to clang-tidy. 2014-10-23 17:23:20 +00:00
ClangTidy.h Add flag --enable-check-profile to clang-tidy. 2014-10-23 17:23:20 +00:00
ClangTidyDiagnosticConsumer.cpp [clang-tidy] Count errors in ClangTidyDiagnosticConsumer 2014-11-20 12:05:51 +00:00
ClangTidyDiagnosticConsumer.h Fixed a typo in a comment. NFC. 2014-12-19 15:37:02 +00:00
ClangTidyModule.cpp [clang-tidy] Default options in modules. 2014-10-16 11:27:57 +00:00
ClangTidyModule.h [clang-tidy] Default options in modules. 2014-10-16 11:27:57 +00:00
ClangTidyModuleRegistry.h clang-tidy: Instantiate llvm::Registry<clang::tidy::ClangTidyModule>. 2014-07-03 14:12:47 +00:00
ClangTidyOptions.cpp [cleanup] Re-sort the #include lines with llvm/utils/sort_includes.py 2015-01-14 11:24:38 +00:00
ClangTidyOptions.h [clang-tidy] Added -system-headers option. 2014-10-28 22:16:13 +00:00
Makefile Add NamespaceCommentCheck to the Google module. 2014-09-22 10:41:39 +00:00
add_new_check.py [clang-tidy] Extended the example check, added a fix-it, etc. 2014-12-09 12:43:09 +00:00