[clang-tidy] UnnecessaryValueParamCheck - only warn for virtual methods
Summary:
As changing virtual methods could break method overrides disable applying the fix and just warn.
Reviewers: alexfh, sbenza
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D21936
llvm-svn: 274552
diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
index d3e4c7f..71dc455 100644
--- a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -118,8 +118,10 @@
"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.
- if (Param->getLocStart().isMacroID())
+ // Do not propose fixes in macros since we cannot place them correctly, or if
+ // function is virtual as it might break overrides.
+ const auto *Method = llvm::dyn_cast<CXXMethodDecl>(Function);
+ if (Param->getLocStart().isMacroID() || (Method && Method->isVirtual()))
return;
for (const auto *FunctionDecl = Function; FunctionDecl != nullptr;
FunctionDecl = FunctionDecl->getPreviousDecl()) {