[PATCH] D56644: [clang-tidy] readability-container-size-empty handle std::string length()

Roman Lebedev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 12 23:51:14 PST 2019


lebedev.ri added a comment.

In D56644#1355436 <https://reviews.llvm.org/D56644#1355436>, @Quolyk wrote:

> For now, I just added tests. I have several questions, as I'm beginner (`ContainerSizeEmptyCheck.cpp`).
>
> 1. Do I have to extend `ValidContainer`, so it recognises `::std::string` with `length()` method  as valid container too or we can assume `::std::string` as valid container by default?
> 2. If `::std::string` is valid container, I just add one more expression to match. Is it correct way?


https://github.com/llvm-mirror/clang-tools-extra/blob/27011d1db0ee4955bab595ab51ebe264e160ed89/clang-tidy/readability/ContainerSizeEmptyCheck.cpp#L40
i think you want to change `ValidContainer` to not only check for `size`, but for `size` or `lenght`.
I.e. replace `hasName("lenght"),` with `anyOf(hasName("size"), hasName("lenght")),`.
And then adjust the diags to dynamically get the actual method name.


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56644/new/

https://reviews.llvm.org/D56644





More information about the cfe-commits mailing list