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

Alexander Kornienko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 15 06:30:04 PST 2019


alexfh added inline comments.
Herald added a project: clang.


================
Comment at: clang-tidy/readability/ContainerSizeEmptyCheck.cpp:65
                                       hasType(references(ValidContainer))))),
-                        callee(cxxMethodDecl(hasName("size"))), WrongUse,
+                        callee(cxxMethodDecl(anyOf(hasName("size"), hasName("length")))), WrongUse,
                         unless(hasAncestor(cxxMethodDecl(
----------------
lebedev.ri wrote:
> lebedev.ri wrote:
> > This line looks too long, clang-format might be too intrusive, so at least
> > ```
> >                         callee(cxxMethodDecl(anyOf(hasName("size"), 
> >                                                    hasName("length")))),
> >                         WrongUse,
> > 
> > ```
> s/`callee(cxxMethodDecl(anyOf(hasName("size"), hasName("length")))), WrongUse,`/`callee(cxxMethodDecl(ContainerLenghtFuncNames)), WrongUse,`/
Please use `hasAnyName(x, y)` instead of `anyOf(hasName(x), hasName(y))`. It's shorter and executes faster (the more arguments it has, the faster it is compared to the corresponding `anyOf(hasName(...), ...)` construct).


================
Comment at: clang-tidy/readability/ContainerSizeEmptyCheck.cpp:207
+         "for emptiness instead of '%0'")
+        << MemberCall->getMethodDecl()->getName()
         << Hint;
----------------
Did you try without `->getName()`? IIUC, it should work as well.


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