summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Berger <flx@google.com>2017-07-26 00:45:41 +0000
committerFelix Berger <flx@google.com>2017-07-26 00:45:41 +0000
commit603ea2df2a997ade68a946cc5c203469a1b8f2c9 (patch)
tree49efd2bbd7bdddaeddbaaa48aee33f7b0d6f455e
parent14d90fd05cbed5fd3fcee492f072a4e5816f20b5 (diff)
downloadbcm5719-llvm-603ea2df2a997ade68a946cc5c203469a1b8f2c9.tar.gz
bcm5719-llvm-603ea2df2a997ade68a946cc5c203469a1b8f2c9.zip
[clang-tidy] Do not issue fixit for explicit template specializations
Summary: Do not issue fixit in UnnecessaryValueParamCheck if the function is an explicit template specialization as this could cause build breakages. Reviewers: alexfh Subscribers: JDevlieghere, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D35718 llvm-svn: 309067
-rw-r--r--clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp16
-rw-r--r--clang-tools-extra/test/clang-tidy/performance-unnecessary-value-param.cpp11
2 files changed, 26 insertions, 1 deletions
diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
index 04b818260ff..0dc47d5db93 100644
--- a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -58,6 +58,18 @@ bool hasLoopStmtAncestor(const DeclRefExpr &DeclRef, const Decl &Decl,
return Matches.empty();
}
+bool isExplicitTemplateSpecialization(const FunctionDecl &Function) {
+ if (const auto *SpecializationInfo = Function.getTemplateSpecializationInfo())
+ if (SpecializationInfo->getTemplateSpecializationKind() ==
+ TSK_ExplicitSpecialization)
+ return true;
+ if (const auto *Method = llvm::dyn_cast<CXXMethodDecl>(&Function))
+ if (Method->getTemplatedKind() == FunctionDecl::TK_MemberSpecialization &&
+ Method->getMemberSpecializationInfo()->isExplicitSpecialization())
+ return true;
+ return false;
+}
+
} // namespace
UnnecessaryValueParamCheck::UnnecessaryValueParamCheck(
@@ -133,9 +145,11 @@ void UnnecessaryValueParamCheck::check(const MatchFinder::MatchResult &Result) {
// 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.
+ // 4. the function is an explicit template specialization.
const auto *Method = llvm::dyn_cast<CXXMethodDecl>(Function);
if (Param->getLocStart().isMacroID() || (Method && Method->isVirtual()) ||
- isReferencedOutsideOfCallExpr(*Function, *Result.Context))
+ isReferencedOutsideOfCallExpr(*Function, *Result.Context) ||
+ isExplicitTemplateSpecialization(*Function))
return;
for (const auto *FunctionDecl = Function; FunctionDecl != nullptr;
FunctionDecl = FunctionDecl->getPreviousDecl()) {
diff --git a/clang-tools-extra/test/clang-tidy/performance-unnecessary-value-param.cpp b/clang-tools-extra/test/clang-tidy/performance-unnecessary-value-param.cpp
index 5491cbb80c0..dcf82df2e38 100644
--- a/clang-tools-extra/test/clang-tidy/performance-unnecessary-value-param.cpp
+++ b/clang-tools-extra/test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -348,3 +348,14 @@ void fun() {
ExpensiveToCopyType E;
NegativeUsingConstructor S(E);
}
+
+template<typename T>
+void templateFunction(T) {
+}
+
+template<>
+void templateFunction<ExpensiveToCopyType>(ExpensiveToCopyType E) {
+ // CHECK-MESSAGES: [[@LINE-1]]:64: warning: the parameter 'E' is copied
+ // CHECK-FIXES: void templateFunction<ExpensiveToCopyType>(ExpensiveToCopyType E) {
+ E.constReference();
+}
OpenPOWER on IntegriCloud