diff options
author | Felix Berger <flx@google.com> | 2016-11-10 01:28:22 +0000 |
---|---|---|
committer | Felix Berger <flx@google.com> | 2016-11-10 01:28:22 +0000 |
commit | 9c841cd7c4336133797cd2e124c86ecb400d3c63 (patch) | |
tree | bca37a6a43482b856c59f5ffe11b4cf7ddc2ac91 /clang-tidy/performance | |
parent | c3a988d80be2e3133f458c3c53173d2c2ce6c1a2 (diff) |
[clang-tidy] Do not issue fix for functions that are referenced outside of callExpr
Summary: Suppress fixes for functions that are referenced within the
compilation unit outside of a call expression as the signature change
could break the code referencing the function.
We still issue a warning in this case so that users can decide to
manually change the function signature.
Reviewers: alexfh, sbenza, aaron.ballman
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D26203
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@286424 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/performance')
-rw-r--r-- | clang-tidy/performance/UnnecessaryValueParamCheck.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/clang-tidy/performance/UnnecessaryValueParamCheck.cpp b/clang-tidy/performance/UnnecessaryValueParamCheck.cpp index 672c81ff..ec99b3a3 100644 --- a/clang-tidy/performance/UnnecessaryValueParamCheck.cpp +++ b/clang-tidy/performance/UnnecessaryValueParamCheck.cpp @@ -39,6 +39,14 @@ bool isSubset(const S &SubsetCandidate, const S &SupersetCandidate) { return true; } +bool isReferencedOutsideOfCallExpr(const FunctionDecl &Function, + ASTContext &Context) { + auto Matches = match(declRefExpr(to(functionDecl(equalsNode(&Function))), + unless(hasAncestor(callExpr()))), + Context); + return !Matches.empty(); +} + } // namespace UnnecessaryValueParamCheck::UnnecessaryValueParamCheck( @@ -118,10 +126,14 @@ void UnnecessaryValueParamCheck::check(const MatchFinder::MatchResult &Result) { "invocation but only used as a const reference; " "consider making it a const reference") << paramNameOrIndex(Param->getName(), Index); - // Do not propose fixes in macros since we cannot place them correctly, or if - // function is virtual as it might break overrides. + // Do not propose fixes when: + // 1. the ParmVarDecl is in a macro, since we cannot place them correctly + // 2. the function is virtual as it might break overrides + // 3. the function is referenced outside of a call expression within the + // compilation unit as the signature change could introduce build errors. const auto *Method = llvm::dyn_cast<CXXMethodDecl>(Function); - if (Param->getLocStart().isMacroID() || (Method && Method->isVirtual())) + if (Param->getLocStart().isMacroID() || (Method && Method->isVirtual()) || + isReferencedOutsideOfCallExpr(*Function, *Result.Context)) return; for (const auto *FunctionDecl = Function; FunctionDecl != nullptr; FunctionDecl = FunctionDecl->getPreviousDecl()) { |