diff options
Diffstat (limited to 'clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp index 034894c..dc2e8a3 100644 --- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp +++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp @@ -104,15 +104,18 @@ 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()))) - .bind(InitFunctionCallId); + // Only allow initialization of a const reference from a free function or + // static member 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(argumentCountIs(0), + callee(functionDecl(returns(hasCanonicalType(matchers::isReferenceToConst())), + unless(cxxMethodDecl(unless(isStatic())))) + .bind(FunctionDeclId))) + .bind(InitFunctionCallId); } AST_MATCHER_FUNCTION_P(StatementMatcher, initializerReturnsReferenceToConst, @@ -232,7 +235,7 @@ UnnecessaryCopyInitialization::UnnecessaryCopyInitialization( Options.get("ExcludedContainerTypes", ""))) {} void UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) { - auto LocalVarCopiedFrom = [this](const internal::Matcher<Expr> &CopyCtorArg) { + auto LocalVarCopiedFrom = [this](const ast_matchers::internal::Matcher<Expr> &CopyCtorArg) { return compoundStmt( forEachDescendant( declStmt( |