llvm-project/clang-tools-extra
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
..
clang-apply-replacements Handle newlines on Windows correctly. 2014-12-09 02:57:56 +00:00
clang-modernize Make LoopConvert work with containers that are used like arrays. 2015-01-12 13:17:56 +00:00
clang-query Remove call to llvm::makeArrayRef. Implicit conversion is sufficient. 2014-08-29 06:05:20 +00:00
clang-rename [cleanup] Re-sort the #include lines with llvm/utils/sort_includes.py 2015-01-14 11:24:38 +00:00
clang-tidy clang-tidy: 'size' call that could be replaced with 'empty' on STL containers 2015-01-15 15:46:58 +00:00
docs docs/conf.py: bump version to 3.7 2015-01-14 18:32:20 +00:00
modularize Make ArgumentsAdjuster an std::function (clang-tools-extra part of D6505). 2014-12-03 17:53:03 +00:00
module-map-checker Update to match clang r223913. 2014-12-10 03:10:06 +00:00
pp-trace Unique_ptrify PPCallbacks ownership. Goes with clang r217474. 2014-09-10 05:07:57 +00:00
remove-cstr-calls [CMake] Add dependencies on clangToolingCore. 2014-10-30 00:44:01 +00:00
test clang-tidy: 'size' call that could be replaced with 'empty' on STL containers 2015-01-15 15:46:58 +00:00
tool-template Fix Makefiles after r220867. 2014-10-29 18:55:41 +00:00
unittests [cleanup] Re-sort the #include lines with llvm/utils/sort_includes.py 2015-01-14 11:24:38 +00:00
.arcconfig Update arc config to new domain. 2014-04-07 10:23:19 +00:00
.gitignore .gitignore: ignore docs/_build 2013-03-03 15:15:12 +00:00
CMakeLists.txt Revert rL215947: "[clang-rename] revert r215839" 2014-08-20 01:39:05 +00:00
CODE_OWNERS.TXT Switching code owner email address. 2013-10-08 16:28:05 +00:00
LICENSE.TXT Update the copyright credits -- Happy new year 2014! 2014-01-01 08:27:31 +00:00
Makefile Revert rL215947: "[clang-rename] revert r215839" 2014-08-20 01:39:05 +00:00
README.txt Reverted Test commit; added new line to the end of README.txt 2013-10-12 20:43:36 +00:00

README.txt

//===----------------------------------------------------------------------===//
// Clang Tools repository
//===----------------------------------------------------------------------===//

Welcome to the repository of extra Clang Tools.  This repository holds tools
that are developed as part of the LLVM compiler infrastructure project and the
Clang frontend.  These tools are kept in a separate "extra" repository to
allow lighter weight checkouts of the core Clang codebase.

This repository is only intended to be checked out inside of a full LLVM+Clang
tree, and in the 'tools/extra' subdirectory of the Clang checkout.

All discussion regarding Clang, Clang-based tools, and code in this repository
should be held using the standard Clang mailing lists:
  http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

Code review for this tree should take place on the standard Clang patch and
commit lists:
  http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

If you find a bug in these tools, please file it in the LLVM bug tracker:
  http://llvm.org/bugs/