[clang-tools-extra] r309067 - [clang-tidy] Do not issue fixit for explicit template specializations
Felix Berger via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 25 17:45:41 PDT 2017
Author: flx
Date: Tue Jul 25 17:45:41 2017
New Revision: 309067
URL: http://llvm.org/viewvc/llvm-project?rev=309067&view=rev
Log:
[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
Modified:
clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param.cpp
Modified: clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp?rev=309067&r1=309066&r2=309067&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp Tue Jul 25 17:45:41 2017
@@ -58,6 +58,18 @@ bool hasLoopStmtAncestor(const DeclRefEx
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(c
// 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()) {
Modified: clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param.cpp?rev=309067&r1=309066&r2=309067&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param.cpp Tue Jul 25 17:45:41 2017
@@ -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();
+}
More information about the cfe-commits
mailing list