[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-initialization: Consider static functions (PR #119974)
Julian Schmidt via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 15 16:33:14 PST 2024
================
@@ -104,14 +104,16 @@ AST_MATCHER_FUNCTION_P(StatementMatcher,
hasArgument(0, hasType(ReceiverType)))));
}
+AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); }
+
AST_MATCHER_FUNCTION(StatementMatcher, isConstRefReturningFunctionCall) {
// Only allow initialization of a const reference from a free function if it
// has no arguments. Otherwise it could return an alias to one of its
// arguments and the arguments need to be checked for const use as well.
return callExpr(callee(functionDecl(returns(hasCanonicalType(
matchers::isReferenceToConst())))
.bind(FunctionDeclId)),
- argumentCountIs(0), unless(callee(cxxMethodDecl())))
+ argumentCountIs(0), unless(callee(cxxMethodDecl(unless(isStatic())))))
----------------
5chmidti wrote:
Please change `of a free function` to `from a call to a free function or static member function` in the comment above.
You can also move the check for the method and static inward:
```
callExpr(callee(functionDecl(returns(hasCanonicalType(matchers::isReferenceToConst())),
unless(cxxMethodDecl(unless(isStatic()))))
.bind(FunctionDeclId)),
argumentCountIs(0))
```
Unrelated to this PR, but if you reorder anyway: please move the `argumentCountIs` to the front inside `callExpr`.
https://github.com/llvm/llvm-project/pull/119974
More information about the cfe-commits
mailing list