[PATCH] 'size' call that could be replaced with 'empty' on STL containers
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 13922 bytes
Desc: not available
More information about the cfe-commits