[PATCH] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr
Mike Crowe via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 10 03:27:19 PST 2023
mikecrowe added inline comments.
================
Comment at: clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp:188
+ callee(functionDecl(hasName("::std::format")))),
+ hasAnyArgument(materializeTemporaryExpr(
+ has(StringCStrCallExpr))))),
----------------
njames93 wrote:
> The limitation about only transforming the first argument can be alleviated by using the `forEachArgumentWithParam` matcher
Thanks for the hint. I did try to overcome this limitation but failed to find `forEachArgumentWithParam`.
I think that I've managed to make `forEachArgumentWithParam` work, but only if I lose the `materializeTemporaryExpr`. I hope that's not essential. I've ended up with:
```C++
Finder->addMatcher(
traverse(TK_AsIs,
callExpr(callee(functionDecl(hasAnyName("::std::print", "::std::format"))),
forEachArgumentWithParam(StringCStrCallExpr, parmVarDecl()))),
this);
```
I suspect that there's something better than the `parmVarDecl()` second parameter to `forEachArgumentWithParam` though.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D143342/new/
https://reviews.llvm.org/D143342
More information about the cfe-commits
mailing list