[PATCH] D37566: [clang-tidy] fixed misc-unused-parameters omitting parameters default value
Pawel Maciocha via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 11 00:32:19 PDT 2017
PriMee updated this revision to Diff 114538.
PriMee added a comment.
Done :) Could you please commit this for me?
https://reviews.llvm.org/D37566
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
@@ -14,15 +14,16 @@
void b(int i = 1) {}
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters]
-// CHECK-FIXES: {{^}}void b(int /*i*/) {}{{$}}
+// CHECK-FIXES: {{^}}void b(int /*i*/ = 1) {}{{$}}
void c(int *i) {}
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: parameter 'i' is unused [misc-unused-parameters]
// CHECK-FIXES: {{^}}void c(int * /*i*/) {}{{$}}
// Unchanged cases
// ===============
-void g(int i); // Don't remove stuff in declarations
+void f(int i); // Don't remove stuff in declarations
+void g(int i = 1);
void h(int i) { (void)i; } // Don't remove used parameters
bool useLambda(int (*fn)(int));
@@ -52,6 +53,11 @@
// CHECK-MESSAGES: :[[@LINE-1]]:33: warning
// CHECK-FIXES: {{^}}static void staticFunctionE()
+static void staticFunctionF(int i = 4);
+// CHECK-FIXES: {{^}}static void staticFunctionF();
+static void staticFunctionF(int i) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:33: warning
+// CHECK-FIXES: {{^}}static void staticFunctionF()
static void someCallSites() {
staticFunctionA(1);
@@ -62,7 +68,12 @@
// CHECK-FIXES: staticFunctionC(2);
staticFunctionD(1, 2, 3);
// CHECK-FIXES: staticFunctionD(1, 3);
- staticFunctionE();
+ staticFunctionE(1);
+// CHECK-FIXES: staticFunctionE();
+ staticFunctionF(1);
+// CHECK-FIXES: staticFunctionF();
+ staticFunctionF();
+// CHECK-FIXES: staticFunctionF();
}
/*
@@ -95,6 +106,9 @@
static void f(int i) {}
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning
// CHECK-FIXES: static void f(int /*i*/) {}
+ static void g(int i = 1) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning
+// CHECK-FIXES: static void g(int /*i*/ = 1) {}
};
namespace {
@@ -108,6 +122,9 @@
void h(int i) {}
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning
// CHECK-FIXES: void h(int /*i*/) {}
+ void s(int i = 1) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning
+// CHECK-FIXES: void s(int /*i*/ = 1) {}
};
void C::f(int i) {}
@@ -125,6 +142,7 @@
// CHECK-FIXES: c.g();
useFunction(&C::h);
+ useFunction(&C::s);;
}
class Base {
Index: clang-tidy/misc/UnusedParametersCheck.cpp
===================================================================
--- clang-tidy/misc/UnusedParametersCheck.cpp
+++ clang-tidy/misc/UnusedParametersCheck.cpp
@@ -138,7 +138,8 @@
if (Function->isExternallyVisible() ||
!Result.SourceManager->isInMainFile(Function->getLocation()) ||
!Indexer->getOtherRefs(Function).empty() || isOverrideMethod(Function)) {
- SourceRange RemovalRange(Param->getLocation(), Param->getLocEnd());
+ SourceRange RemovalRange(Param->getLocation(),
+ Param->DeclaratorDecl::getSourceRange().getEnd());
// Note: We always add a space before the '/*' to not accidentally create a
// '*/*' for pointer types, which doesn't start a comment. clang-format will
// clean this up afterwards.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37566.114538.patch
Type: text/x-patch
Size: 3115 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170911/98d520a4/attachment.bin>
More information about the cfe-commits
mailing list