[PATCH] D37846: [clang-tidy] Fixed misc-unused-parameters omitting parameters square brackets
Pawel Maciocha via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 14 01:48:36 PDT 2017
PriMee created this revision.
PriMee added a project: clang-tools-extra.
Herald added subscribers: xazax.hun, JDevlieghere.
Bug: https://bugs.llvm.org/show_bug.cgi?id=34449
**Problem:**
Clang-tidy check misc-unused-parameters comments out parameter name omitting following characters (e.g. square brackets) what results in its complete removal. Compilation errors might occur after clang-tidy fix as well.
**Patch description:**
Changed removal range. The range should end after parameter name, not after whole parameter declarator (which might be followed by e.g. square brackets).
Repository:
rL LLVM
https://reviews.llvm.org/D37846
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
@@ -20,11 +20,21 @@
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: parameter 'i' is unused [misc-unused-parameters]
// CHECK-FIXES: {{^}}void c(int * /*i*/) {}{{$}}
+void d(int i[]) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters]
+// CHECK-FIXES: {{^}}void d(int /*i*/[]) {}{{$}}
+
+void e(int i[1]) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters]
+// CHECK-FIXES: {{^}}void e(int /*i*/[1]) {}{{$}}
+
// Unchanged cases
// ===============
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
+void h(int i[]);
+void s(int i[1]);
+void u(int i) { (void)i; } // Don't remove used parameters
bool useLambda(int (*fn)(int));
static bool static_var = useLambda([] (int a) { return a; });
@@ -109,6 +119,9 @@
static void g(int i = 1) {}
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning
// CHECK-FIXES: static void g(int /*i*/ = 1) {}
+ static void h(int i[]) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning
+// CHECK-FIXES: static void h(int /*i*/[]) {}
};
namespace {
@@ -125,6 +138,9 @@
void s(int i = 1) {}
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning
// CHECK-FIXES: void s(int /*i*/ = 1) {}
+ void u(int i[]) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning
+// CHECK-FIXES: void u(int /*i*/[]) {}
};
void C::f(int i) {}
@@ -142,7 +158,8 @@
// CHECK-FIXES: c.g();
useFunction(&C::h);
- useFunction(&C::s);;
+ useFunction(&C::s);
+ useFunction(&C::u);
}
class Base {
Index: clang-tidy/misc/UnusedParametersCheck.cpp
===================================================================
--- clang-tidy/misc/UnusedParametersCheck.cpp
+++ clang-tidy/misc/UnusedParametersCheck.cpp
@@ -138,8 +138,7 @@
if (Function->isExternallyVisible() ||
!Result.SourceManager->isInMainFile(Function->getLocation()) ||
!Indexer->getOtherRefs(Function).empty() || isOverrideMethod(Function)) {
- SourceRange RemovalRange(Param->getLocation(),
- Param->DeclaratorDecl::getSourceRange().getEnd());
+ SourceRange RemovalRange(Param->getLocation(), Param->Decl::getLocation());
// 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: D37846.115187.patch
Type: text/x-patch
Size: 2632 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170914/ead0fe91/attachment.bin>
More information about the cfe-commits
mailing list