forked from OSchip/llvm-project
[clang-tidy] fixed misc-unused-parameters omitting parameters default value
Summary: Bug: https://bugs.llvm.org/show_bug.cgi?id=34450 **Problem:** Clang-tidy check misc-unused-parameters omits parameter default value what results in its complete removal. Compilation errors might occur after clang-tidy fix. **Patch description:** Changed removal range. The range should end after parameter declarator, not after whole parameter declaration (which might contain a default value). Reviewers: alexfh, xazax.hun Reviewed By: alexfh Subscribers: JDevlieghere, cfe-commits Tags: #clang-tools-extra Patch by Pawel Maciocha! Differential Revision: https://reviews.llvm.org/D37566 llvm-svn: 313150
This commit is contained in:
parent
50e068158b
commit
e5590927d6
|
@ -138,7 +138,8 @@ void UnusedParametersCheck::warnOnUnusedParameter(
|
|||
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.
|
||||
|
|
|
@ -14,7 +14,7 @@ void a(int i) {}
|
|||
|
||||
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]
|
||||
|
@ -22,7 +22,8 @@ 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 @@ static void staticFunctionE(int i = 4) {}
|
|||
// 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 @@ static void someCallSites() {
|
|||
// 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 @@ class SomeClass {
|
|||
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 @@ public:
|
|||
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 @@ void someMoreCallSites() {
|
|||
// CHECK-FIXES: c.g();
|
||||
|
||||
useFunction(&C::h);
|
||||
useFunction(&C::s);;
|
||||
}
|
||||
|
||||
class Base {
|
||||
|
|
Loading…
Reference in New Issue