[PATCH] D158346: [clang-tidy] [readability-container-size-empty] improved check to detect missing usage of .empty() on string_literals Fixes #64547

Piotr Zegar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 19 12:30:36 PDT 2023


PiotrZSL requested changes to this revision.
PiotrZSL added a comment.
This revision now requires changes to proceed.

- Release notes entry is missing.
- Commit/Change description should be updated



================
Comment at: clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp:171
+      anyOf(stringLiteral(hasSize(0)),
+            userDefinedLiteral(hasDescendant(stringLiteral(hasSize(0)))),
+            cxxConstructExpr(isDefaultConstruction()),
----------------
Probably best would be to write matcher like this:

```
AST_MATCHER_P(UserDefinedLiteral, hasLiteral, Matcher<Expr>, InnerMatcher) {
   if (const Expr* CookedLiteral  = Node.getCookedLiteral()) {
      return InnerMatcher.matches(CookedLiteral, Finder, Builder);
   }
   return false;
}
```
and use it instead of hasDescendant
```
userDefinedLiteral(hasLiteral(stringLiteral(hasSize(0)))),
```


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp:791
+}
\ No newline at end of file

----------------
Add this new line


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158346



More information about the cfe-commits mailing list