Skip to content

Commit 240a2e2

Browse files
committedSep 4, 2019
[clang-tidy] Fix bugprone-argument-comment bug if there are marcos.
Summary: Fix bugprone-argument-comment bug if there are marcos. For example: ``` void j(int a, int b, int c); j(X(1), /*b=*/1, X(1)); ``` clang-tidy can't recognize comment "/*b=*/". It suggests fix like this: ``` j(X(1), /*b=*//*b=*/1, X(1)); ``` This change tries to fix this issue. Reviewers: alexfh, hokein, aaron.ballman Reviewed By: alexfh Subscribers: xazax.hun, cfe-commits Tags: #clang, #clang-tools-extra Patch by Yubo Xie. Differential Revision: https://reviews.llvm.org/D67080 llvm-svn: 370919
1 parent 80913a7 commit 240a2e2

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed
 

‎clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
286286
Comments = getCommentsInRange(Ctx, BeforeArgument);
287287
} else {
288288
// Fall back to parsing back from the start of the argument.
289-
CharSourceRange ArgsRange = MakeFileCharRange(
290-
Args[I]->getBeginLoc(), Args[NumArgs - 1]->getEndLoc());
289+
CharSourceRange ArgsRange =
290+
MakeFileCharRange(Args[I]->getBeginLoc(), Args[I]->getEndLoc());
291291
Comments = getCommentsBeforeLoc(Ctx, ArgsRange.getBegin());
292292
}
293293

‎clang-tools-extra/test/clang-tidy/bugprone-argument-comment-literals.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ struct A {
1515
};
1616

1717
#define FOO 1
18+
#define X(x) (x)
1819

1920
void g(int a);
2021
void h(double b);
2122
void i(const char *c);
23+
void j(int a, int b, int c);
2224

2325
double operator"" _km(long double);
2426

@@ -106,6 +108,39 @@ void test() {
106108
// CHECK-FIXES: h(/*b=*/1.0f);
107109
i(__FILE__);
108110

111+
j(1, X(1), X(1));
112+
// CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument comment missing for literal argument 'a' [bugprone-argument-comment]
113+
// CHECK-FIXES: j(/*a=*/1, X(1), X(1));
114+
j(/*a=*/1, X(1), X(1));
115+
116+
j(X(1), 1, X(1));
117+
// CHECK-MESSAGES: [[@LINE-1]]:11: warning: argument comment missing for literal argument 'b' [bugprone-argument-comment]
118+
// CHECK-FIXES: j(X(1), /*b=*/1, X(1));
119+
j(X(1), /*b=*/1, X(1));
120+
121+
j(X(1), X(1), 1);
122+
// CHECK-MESSAGES: [[@LINE-1]]:17: warning: argument comment missing for literal argument 'c' [bugprone-argument-comment]
123+
// CHECK-FIXES: j(X(1), X(1), /*c=*/1);
124+
j(X(1), X(1), /*c=*/1);
125+
126+
j(X(1), 1, 1);
127+
// CHECK-MESSAGES: [[@LINE-1]]:11: warning: argument comment missing for literal argument 'b' [bugprone-argument-comment]
128+
// CHECK-MESSAGES: [[@LINE-2]]:14: warning: argument comment missing for literal argument 'c' [bugprone-argument-comment]
129+
// CHECK-FIXES: j(X(1), /*b=*/1, /*c=*/1);
130+
j(X(1), /*b=*/1, /*c=*/1);
131+
132+
j(1, X(1), 1);
133+
// CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument comment missing for literal argument 'a' [bugprone-argument-comment]
134+
// CHECK-MESSAGES: [[@LINE-2]]:14: warning: argument comment missing for literal argument 'c' [bugprone-argument-comment]
135+
// CHECK-FIXES: j(/*a=*/1, X(1), /*c=*/1);
136+
j(/*a=*/1, X(1), /*c=*/1);
137+
138+
j(1, 1, X(1));
139+
// CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument comment missing for literal argument 'a' [bugprone-argument-comment]
140+
// CHECK-MESSAGES: [[@LINE-2]]:8: warning: argument comment missing for literal argument 'b' [bugprone-argument-comment]
141+
// CHECK-FIXES: j(/*a=*/1, /*b=*/1, X(1));
142+
j(/*a=*/1, /*b=*/1, X(1));
143+
109144
// FIXME Would like the below to add argument comments.
110145
g((1));
111146
// FIXME But we should not add argument comments here.

0 commit comments

Comments
 (0)
Please sign in to comment.