[PATCH] D37566: [clang-tidy] fixed misc-unused-parameters omitting parameters default value
Alexander Kornienko via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 13 07:56:45 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL313150: [clang-tidy] fixed misc-unused-parameters omitting parameters default value (authored by alexfh).
Changed prior to commit:
https://reviews.llvm.org/D37566?vs=114538&id=115047#toc
Repository:
rL LLVM
https://reviews.llvm.org/D37566
Files:
clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp
Index: clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
+++ clang-tools-extra/trunk/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.
Index: clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp
+++ clang-tools-extra/trunk/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 {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37566.115047.patch
Type: text/x-patch
Size: 3259 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170913/371ca3ac/attachment.bin>
More information about the cfe-commits
mailing list