Author: George Burgess IV Date: 2021-08-03T19:56:27Z New Revision: 2e75986a21e543ac9f169a067542eec590339ac0
URL: https://github.com/llvm/llvm-project/commit/2e75986a21e543ac9f169a067542eec590339ac0 DIFF: https://github.com/llvm/llvm-project/commit/2e75986a21e543ac9f169a067542eec590339ac0.diff LOG: bugprone-argument-comment: ignore mismatches from system headers As of 2a3498e24f97d, we ignore parameter name mismatches for functions in the `std::` namespace, since those aren't standardized. It seems reasonable to extend this to all functions which are declared in system headers, since this lint can be a bit noisy otherwise (https://bugs.chromium.org/p/chromium/issues/detail?id=1191507). Differential Revision: https://reviews.llvm.org/D99993 Added: clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-argument-comment/header-with-decl.h clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-argument-comment/system-header-with-decl.h Modified: clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp index e50ebdba3b34..c36fb60b6d3d 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp @@ -20,10 +20,12 @@ namespace clang { namespace tidy { namespace bugprone { namespace { -AST_MATCHER(Decl, isFromStdNamespace) { +AST_MATCHER(Decl, isFromStdNamespaceOrSystemHeader) { if (const auto *D = Node.getDeclContext()->getEnclosingNamespaceContext()) - return D->isStdNamespace(); - return false; + if (D->isStdNamespace()) + return true; + return Node.getASTContext().getSourceManager().isInSystemHeader( + Node.getLocation()); } } // namespace @@ -66,13 +68,13 @@ void ArgumentCommentCheck::registerMatchers(MatchFinder *Finder) { // not specified by the standard, and standard library // implementations in practice have to use reserved names to // avoid conflicts with same-named macros. - unless(hasDeclaration(isFromStdNamespace()))) - .bind("expr"), - this); - Finder->addMatcher( - cxxConstructExpr(unless(hasDeclaration(isFromStdNamespace()))) + unless(hasDeclaration(isFromStdNamespaceOrSystemHeader()))) .bind("expr"), this); + Finder->addMatcher(cxxConstructExpr(unless(hasDeclaration( + isFromStdNamespaceOrSystemHeader()))) + .bind("expr"), + this); } static std::vector<std::pair<SourceLocation, StringRef>> diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-argument-comment/header-with-decl.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-argument-comment/header-with-decl.h new file mode 100644 index 000000000000..1e065b1edeb6 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-argument-comment/header-with-decl.h @@ -0,0 +1 @@ +void my_header_function(int arg); diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-argument-comment/system-header-with-decl.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-argument-comment/system-header-with-decl.h new file mode 100644 index 000000000000..4e3529a6f1ab --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-argument-comment/system-header-with-decl.h @@ -0,0 +1,3 @@ +#pragma clang system_header + +void my_system_header_function(int arg); diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp index 8a6fe097a55d..cb4eac84c691 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy %s bugprone-argument-comment %t +// RUN: %check_clang_tidy %s bugprone-argument-comment %t -- -- -I %S/Inputs/bugprone-argument-comment // FIXME: clang-tidy should provide a -verify mode to make writing these checks // easier and more accurate. @@ -134,3 +134,20 @@ void test(int a, int b) { std::swap(a, /*num=*/b); } } // namespace ignore_std_functions + +namespace regular_header { +#include "header-with-decl.h" +void test() { + my_header_function(/*not_arg=*/1); +// CHECK-NOTES: [[@LINE-1]]:22: warning: argument name 'not_arg' in comment does not match parameter name 'arg' +// CHECK-NOTES: header-with-decl.h:1:29: note: 'arg' declared here +// CHECK-FIXES: my_header_function(/*not_arg=*/1); +} +} // namespace regular_header + +namespace system_header { +#include "system-header-with-decl.h" +void test() { + my_system_header_function(/*not_arg=*/1); +} +} // namespace system_header _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits