[clang-tidy] Fix bugprone-argument-comment bug: negative literal number is not checked.
Summary: For example: ``` void foo(int a); foo(-2); ``` should be fixed as: ``` foo(/*a=*/-2); ``` This change tries to fix this issue. Reviewers: alexfh, hokein, aaron.ballman Reviewed By: alexfh, aaron.ballman Subscribers: xazax.hun, cfe-commits Tags: #clang, #clang-tools-extra Patch by Yubo Xie. Differential Revision: https://reviews.llvm.org/D67084 llvm-svn: 371072
This commit is contained in:
parent
4e14bf71b7
commit
b6d9703050
|
@ -230,9 +230,11 @@ static const FunctionDecl *resolveMocks(const FunctionDecl *Func) {
|
||||||
// Given the argument type and the options determine if we should
|
// Given the argument type and the options determine if we should
|
||||||
// be adding an argument comment.
|
// be adding an argument comment.
|
||||||
bool ArgumentCommentCheck::shouldAddComment(const Expr *Arg) const {
|
bool ArgumentCommentCheck::shouldAddComment(const Expr *Arg) const {
|
||||||
|
Arg = Arg->IgnoreImpCasts();
|
||||||
|
if (isa<UnaryOperator>(Arg))
|
||||||
|
Arg = cast<UnaryOperator>(Arg)->getSubExpr();
|
||||||
if (Arg->getExprLoc().isMacroID())
|
if (Arg->getExprLoc().isMacroID())
|
||||||
return false;
|
return false;
|
||||||
Arg = Arg->IgnoreImpCasts();
|
|
||||||
return (CommentBoolLiterals && isa<CXXBoolLiteralExpr>(Arg)) ||
|
return (CommentBoolLiterals && isa<CXXBoolLiteralExpr>(Arg)) ||
|
||||||
(CommentIntegerLiterals && isa<IntegerLiteral>(Arg)) ||
|
(CommentIntegerLiterals && isa<IntegerLiteral>(Arg)) ||
|
||||||
(CommentFloatLiterals && isa<FloatingLiteral>(Arg)) ||
|
(CommentFloatLiterals && isa<FloatingLiteral>(Arg)) ||
|
||||||
|
|
|
@ -69,18 +69,29 @@ void test() {
|
||||||
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: argument comment missing for literal argument 'fabc' [bugprone-argument-comment]
|
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: argument comment missing for literal argument 'fabc' [bugprone-argument-comment]
|
||||||
// CHECK-FIXES: a.foo(/*fabc=*/1.0f);
|
// CHECK-FIXES: a.foo(/*fabc=*/1.0f);
|
||||||
|
|
||||||
|
a.foo(-1.0f);
|
||||||
|
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: argument comment missing for literal argument 'fabc' [bugprone-argument-comment]
|
||||||
|
// CHECK-FIXES: a.foo(/*fabc=*/-1.0f);
|
||||||
|
|
||||||
a.foo(1.0);
|
a.foo(1.0);
|
||||||
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: argument comment missing for literal argument 'dabc' [bugprone-argument-comment]
|
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: argument comment missing for literal argument 'dabc' [bugprone-argument-comment]
|
||||||
// CHECK-FIXES: a.foo(/*dabc=*/1.0);
|
// CHECK-FIXES: a.foo(/*dabc=*/1.0);
|
||||||
|
|
||||||
|
a.foo(-1.0);
|
||||||
|
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: argument comment missing for literal argument 'dabc' [bugprone-argument-comment]
|
||||||
|
// CHECK-FIXES: a.foo(/*dabc=*/-1.0);
|
||||||
|
|
||||||
int val3 = 10;
|
int val3 = 10;
|
||||||
a.foo(val3);
|
a.foo(val3);
|
||||||
|
a.foo(-val3);
|
||||||
|
|
||||||
float val4 = 10.0;
|
float val4 = 10.0;
|
||||||
a.foo(val4);
|
a.foo(val4);
|
||||||
|
a.foo(-val4);
|
||||||
|
|
||||||
double val5 = 10.0;
|
double val5 = 10.0;
|
||||||
a.foo(val5);
|
a.foo(val5);
|
||||||
|
a.foo(-val5);
|
||||||
|
|
||||||
a.foo("Hello World");
|
a.foo("Hello World");
|
||||||
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: argument comment missing for literal argument 'strabc' [bugprone-argument-comment]
|
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: argument comment missing for literal argument 'strabc' [bugprone-argument-comment]
|
||||||
|
@ -98,14 +109,22 @@ void test() {
|
||||||
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: argument comment missing for literal argument 'dabc' [bugprone-argument-comment]
|
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: argument comment missing for literal argument 'dabc' [bugprone-argument-comment]
|
||||||
// CHECK-FIXES: a.foo(/*dabc=*/402.0_km);
|
// CHECK-FIXES: a.foo(/*dabc=*/402.0_km);
|
||||||
|
|
||||||
|
a.foo(-402.0_km);
|
||||||
|
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: argument comment missing for literal argument 'dabc' [bugprone-argument-comment]
|
||||||
|
// CHECK-FIXES: a.foo(/*dabc=*/-402.0_km);
|
||||||
|
|
||||||
a.foo('A');
|
a.foo('A');
|
||||||
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: argument comment missing for literal argument 'chabc' [bugprone-argument-comment]
|
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: argument comment missing for literal argument 'chabc' [bugprone-argument-comment]
|
||||||
// CHECK-FIXES: a.foo(/*chabc=*/'A');
|
// CHECK-FIXES: a.foo(/*chabc=*/'A');
|
||||||
|
|
||||||
g(FOO);
|
g(FOO);
|
||||||
|
g(-FOO);
|
||||||
h(1.0f);
|
h(1.0f);
|
||||||
// CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument comment missing for literal argument 'b' [bugprone-argument-comment]
|
// CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument comment missing for literal argument 'b' [bugprone-argument-comment]
|
||||||
// CHECK-FIXES: h(/*b=*/1.0f);
|
// CHECK-FIXES: h(/*b=*/1.0f);
|
||||||
|
h(-1.0f);
|
||||||
|
// CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument comment missing for literal argument 'b' [bugprone-argument-comment]
|
||||||
|
// CHECK-FIXES: h(/*b=*/-1.0f);
|
||||||
i(__FILE__);
|
i(__FILE__);
|
||||||
|
|
||||||
j(1, X(1), X(1));
|
j(1, X(1), X(1));
|
||||||
|
|
Loading…
Reference in New Issue