[PATCH] D35718: [clang-tidy] Do not issue fixit for explicit template specializations
Felix Berger via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 25 17:46:49 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL309067: [clang-tidy] Do not issue fixit for explicit template specializations (authored by flx).
Changed prior to commit:
https://reviews.llvm.org/D35718?vs=107786&id=108193#toc
Repository:
rL LLVM
https://reviews.llvm.org/D35718
Files:
clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param.cpp
Index: clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -58,6 +58,18 @@
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 @@
// 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()) {
Index: clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -348,3 +348,14 @@
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();
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35718.108193.patch
Type: text/x-patch
Size: 2488 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170726/14319380/attachment.bin>
More information about the cfe-commits
mailing list