[clang-tools-extra] [clang-tidy] Extend readability-container-size-empty to std::size() (PR #201231)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 3 03:48:40 PDT 2026
================
@@ -208,6 +208,19 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
.bind("SizeCallExpr"),
this);
+ // Match non-member std::size(container) used in boolean context or compared
+ // with 0/1.
+ Finder->addMatcher(
+ callExpr(argumentCountIs(1),
+ callee(functionDecl(hasName("::std::size")).bind("SizeMethod")),
+ hasArgument(0, expr(anyOf(hasType(ValidContainer),
+ hasType(pointsTo(ValidContainer)),
+ hasType(references(ValidContainer))))
+ .bind("MemberCallObject")),
----------------
vbvictor wrote:
expr(anyOf(....)) can be refactored in separate matcher to avoid duplication with previous , could be corrected later.
https://github.com/llvm/llvm-project/pull/201231
More information about the cfe-commits
mailing list