diff options
3 files changed, 16 insertions, 13 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.cpp b/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.cpp index a69aaecce1c..a0bdd8a98ed 100644 --- a/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.cpp @@ -37,8 +37,8 @@ void ArgumentCommentCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher(cxxConstructExpr().bind("expr"), this); } -std::vector<std::pair<SourceLocation, StringRef>> -ArgumentCommentCheck::getCommentsInRange(ASTContext *Ctx, SourceRange Range) { +static std::vector<std::pair<SourceLocation, StringRef>> +getCommentsInRange(ASTContext *Ctx, CharSourceRange Range) { std::vector<std::pair<SourceLocation, StringRef>> Comments; auto &SM = Ctx->getSourceManager(); std::pair<FileID, unsigned> BeginLoc = SM.getDecomposedLoc(Range.getBegin()), @@ -132,16 +132,13 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx, } } - SourceLocation BeginSLoc, EndSLoc = Args[i]->getLocStart(); - if (i == 0) - BeginSLoc = ArgBeginLoc; - else - BeginSLoc = Args[i - 1]->getLocEnd(); - if (BeginSLoc.isMacroID() || EndSLoc.isMacroID()) - continue; + CharSourceRange BeforeArgument = CharSourceRange::getCharRange( + i == 0 ? ArgBeginLoc : Args[i - 1]->getLocEnd(), + Args[i]->getLocStart()); + BeforeArgument = Lexer::makeFileCharRange( + BeforeArgument, Ctx->getSourceManager(), Ctx->getLangOpts()); - for (auto Comment : - getCommentsInRange(Ctx, SourceRange(BeginSLoc, EndSLoc))) { + for (auto Comment : getCommentsInRange(Ctx, BeforeArgument)) { llvm::SmallVector<StringRef, 2> Matches; if (IdentRE.match(Comment.second, &Matches)) { if (Matches[2] != II->getName()) { diff --git a/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.h b/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.h index f37e408dd24..51ad7345779 100644 --- a/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.h +++ b/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.h @@ -43,8 +43,6 @@ private: bool isLikelyTypo(llvm::ArrayRef<ParmVarDecl *> Params, StringRef ArgName, unsigned ArgIndex); - std::vector<std::pair<SourceLocation, StringRef>> - getCommentsInRange(ASTContext *Ctx, SourceRange Range); void checkCallArgs(ASTContext *Ctx, const FunctionDecl *Callee, SourceLocation ArgBeginLoc, llvm::ArrayRef<const Expr *> Args); diff --git a/clang-tools-extra/test/clang-tidy/misc-argument-comment.cpp b/clang-tools-extra/test/clang-tidy/misc-argument-comment.cpp index 93217b0f57a..80180eeaba2 100644 --- a/clang-tools-extra/test/clang-tidy/misc-argument-comment.cpp +++ b/clang-tools-extra/test/clang-tidy/misc-argument-comment.cpp @@ -12,6 +12,7 @@ void g() { // CHECK-MESSAGES: [[@LINE+2]]:14: warning: argument name 'z' in comment does not match parameter name 'y' // CHECK-MESSAGES: :[[@LINE-5]]:19: note: 'y' declared here f(/*y=*/0, /*z=*/0); + // CHECK-FIXES: {{^}} f(/*y=*/0, /*z=*/0); } struct Closure {}; @@ -37,4 +38,11 @@ void templates() { variadic(/*xxx=*/0, /*yyy=*/1); variadic2(/*zzZ=*/0, /*xxx=*/1, /*yyy=*/2); // CHECK-MESSAGES: [[@LINE-1]]:13: warning: argument name 'zzZ' in comment does not match parameter name 'zzz' + // CHECK-FIXES: variadic2(/*zzz=*/0, /*xxx=*/1, /*yyy=*/2); } + +#define FALSE 0 +void qqq(bool aaa); +void f() { qqq(/*bbb=*/FALSE); } +// CHECK-MESSAGES: [[@LINE-1]]:16: warning: argument name 'bbb' in comment does not match parameter name 'aaa' +// CHECK-FIXES: void f() { qqq(/*bbb=*/FALSE); } |