summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp4
-rw-r--r--clang-tools-extra/test/clang-tidy/bugprone-argument-comment-literals.cpp35
2 files changed, 37 insertions, 2 deletions
diff --git a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
index 5d6c7c9a4ca..07219f9c724 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
@@ -286,8 +286,8 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
Comments = getCommentsInRange(Ctx, BeforeArgument);
} else {
// Fall back to parsing back from the start of the argument.
- CharSourceRange ArgsRange = MakeFileCharRange(
- Args[I]->getBeginLoc(), Args[NumArgs - 1]->getEndLoc());
+ CharSourceRange ArgsRange =
+ MakeFileCharRange(Args[I]->getBeginLoc(), Args[I]->getEndLoc());
Comments = getCommentsBeforeLoc(Ctx, ArgsRange.getBegin());
}
diff --git a/clang-tools-extra/test/clang-tidy/bugprone-argument-comment-literals.cpp b/clang-tools-extra/test/clang-tidy/bugprone-argument-comment-literals.cpp
index 739c9a59397..79ae4c45103 100644
--- a/clang-tools-extra/test/clang-tidy/bugprone-argument-comment-literals.cpp
+++ b/clang-tools-extra/test/clang-tidy/bugprone-argument-comment-literals.cpp
@@ -15,10 +15,12 @@ struct A {
};
#define FOO 1
+#define X(x) (x)
void g(int a);
void h(double b);
void i(const char *c);
+void j(int a, int b, int c);
double operator"" _km(long double);
@@ -106,6 +108,39 @@ void test() {
// CHECK-FIXES: h(/*b=*/1.0f);
i(__FILE__);
+ j(1, X(1), X(1));
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument comment missing for literal argument 'a' [bugprone-argument-comment]
+ // CHECK-FIXES: j(/*a=*/1, X(1), X(1));
+ j(/*a=*/1, X(1), X(1));
+
+ j(X(1), 1, X(1));
+ // CHECK-MESSAGES: [[@LINE-1]]:11: warning: argument comment missing for literal argument 'b' [bugprone-argument-comment]
+ // CHECK-FIXES: j(X(1), /*b=*/1, X(1));
+ j(X(1), /*b=*/1, X(1));
+
+ j(X(1), X(1), 1);
+ // CHECK-MESSAGES: [[@LINE-1]]:17: warning: argument comment missing for literal argument 'c' [bugprone-argument-comment]
+ // CHECK-FIXES: j(X(1), X(1), /*c=*/1);
+ j(X(1), X(1), /*c=*/1);
+
+ j(X(1), 1, 1);
+ // CHECK-MESSAGES: [[@LINE-1]]:11: warning: argument comment missing for literal argument 'b' [bugprone-argument-comment]
+ // CHECK-MESSAGES: [[@LINE-2]]:14: warning: argument comment missing for literal argument 'c' [bugprone-argument-comment]
+ // CHECK-FIXES: j(X(1), /*b=*/1, /*c=*/1);
+ j(X(1), /*b=*/1, /*c=*/1);
+
+ j(1, X(1), 1);
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument comment missing for literal argument 'a' [bugprone-argument-comment]
+ // CHECK-MESSAGES: [[@LINE-2]]:14: warning: argument comment missing for literal argument 'c' [bugprone-argument-comment]
+ // CHECK-FIXES: j(/*a=*/1, X(1), /*c=*/1);
+ j(/*a=*/1, X(1), /*c=*/1);
+
+ j(1, 1, X(1));
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: argument comment missing for literal argument 'a' [bugprone-argument-comment]
+ // CHECK-MESSAGES: [[@LINE-2]]:8: warning: argument comment missing for literal argument 'b' [bugprone-argument-comment]
+ // CHECK-FIXES: j(/*a=*/1, /*b=*/1, X(1));
+ j(/*a=*/1, /*b=*/1, X(1));
+
// FIXME Would like the below to add argument comments.
g((1));
// FIXME But we should not add argument comments here.
OpenPOWER on IntegriCloud