[PATCH] D11417: Fix misc-unused-parameters handling of function templates
Scott Wallace
scottwallace.dev at gmail.com
Wed Jul 22 09:42:55 PDT 2015
swallace updated this revision to Diff 30362.
swallace added a comment.
Add a couple of cases showing that unused parameters in function templates do correctly get removed.
http://reviews.llvm.org/D11417
Files:
clang-tidy/misc/UnusedParametersCheck.cpp
test/clang-tidy/misc-unused-parameters.cpp
Index: test/clang-tidy/misc-unused-parameters.cpp
===================================================================
--- test/clang-tidy/misc-unused-parameters.cpp
+++ test/clang-tidy/misc-unused-parameters.cpp
@@ -88,3 +88,14 @@
}
} // end namespace
+
+template <typename T> void someFunctionTemplate(T b, T e) { (void)b; (void)e; }
+
+template <typename T> void someFunctionTemplateOneUnusedParam(T b, T e) { (void)e; }
+// CHECK-MESSAGES: :[[@LINE-1]]:65: warning
+// CHECK-FIXES: {{^}}template <typename T> void someFunctionTemplateOneUnusedParam(T /*b*/, T e) { (void)e; }
+
+template <typename T> void someFunctionTemplateAllUnusedParams(T b, T e) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:66: warning
+// CHECK-MESSAGES: :[[@LINE-2]]:71: warning
+// CHECK-FIXES: {{^}}template <typename T> void someFunctionTemplateAllUnusedParams(T /*b*/, T /*e*/) {}
Index: clang-tidy/misc/UnusedParametersCheck.cpp
===================================================================
--- clang-tidy/misc/UnusedParametersCheck.cpp
+++ clang-tidy/misc/UnusedParametersCheck.cpp
@@ -59,7 +59,8 @@
if (!Function->doesThisDeclarationHaveABody())
return;
const auto *Param = Result.Nodes.getNodeAs<ParmVarDecl>("x");
- if (Param->isUsed())
+ if (Param->isUsed() || Param->isReferenced() || !Param->getDeclName() ||
+ Param->hasAttr<UnusedAttr>())
return;
auto MyDiag = diag(Param->getLocation(), "parameter '%0' is unused")
@@ -102,4 +103,3 @@
} // namespace tidy
} // namespace clang
-
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11417.30362.patch
Type: text/x-patch
Size: 1506 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150722/8746dd93/attachment.bin>
More information about the cfe-commits
mailing list