File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,17 @@ bool isOverrideMethod(const FunctionDecl *Function) {
26
26
return MD->size_overridden_methods () > 0 || MD->hasAttr <OverrideAttr>();
27
27
return false ;
28
28
}
29
+
30
+ bool hasAttrAfterParam (const clang::SourceManager *SourceManager,
31
+ const ParmVarDecl *Param) {
32
+ for (const auto *Attr : Param->attrs ()) {
33
+ if (SourceManager->isBeforeInTranslationUnit (Param->getLocation (),
34
+ Attr->getLocation ())) {
35
+ return true ;
36
+ }
37
+ }
38
+ return false ;
39
+ }
29
40
} // namespace
30
41
31
42
void UnusedParametersCheck::registerMatchers (MatchFinder *Finder) {
@@ -189,6 +200,11 @@ void UnusedParametersCheck::check(const MatchFinder::MatchResult &Result) {
189
200
if (Param->isUsed () || Param->isReferenced () || !Param->getDeclName () ||
190
201
Param->hasAttr <UnusedAttr>())
191
202
continue ;
203
+ if (hasAttrAfterParam (Result.SourceManager , Param)) {
204
+ // Due to how grammar works, attributes would be wrongly applied to the
205
+ // type if we remove the preceding parameter name.
206
+ continue ;
207
+ }
192
208
193
209
// In non-strict mode ignore function definitions with empty bodies
194
210
// (constructor initializer counts for non-empty body).
Original file line number Diff line number Diff line change @@ -33,6 +33,10 @@ void f(void (*fn)()) {;}
33
33
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: parameter 'fn' is unused [misc-unused-parameters]
34
34
// CHECK-FIXES: {{^}}void f(void (* /*fn*/)()) {;}{{$}}
35
35
36
+ int *k ([[clang::lifetimebound]] int *i) {;}
37
+ // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: parameter 'i' is unused [misc-unused-parameters]
38
+ // CHECK-FIXES: {{^}}int *k({{\[\[clang::lifetimebound\]\]}} int * /*i*/) {;}{{$}}
39
+
36
40
// Unchanged cases
37
41
// ===============
38
42
void f (int i); // Don't remove stuff in declarations
@@ -41,6 +45,7 @@ void h(int i[]);
41
45
void s (int i[1 ]);
42
46
void u (void (*fn)());
43
47
void w (int i) { (void )i; } // Don't remove used parameters
48
+ int *x (int *i [[clang::lifetimebound]]) { return nullptr ; } // Don't reanchor attribute to the type.
44
49
45
50
bool useLambda (int (*fn)(int ));
46
51
static bool static_var = useLambda([] (int a) { return a; });
You can’t perform that action at this time.
0 commit comments