hokein updated this revision to Diff 262556. hokein marked 3 inline comments as done. hokein added a comment.
address comment. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D79494/new/ https://reviews.llvm.org/D79494 Files: clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp +++ clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp @@ -115,3 +115,22 @@ // CHECK-NOTES: [[@LINE-3]]:13: note: 'xxx' declared here // CHECK-FIXES: void g() { f6(/*xxy=*/0, 0); } } + + +namespace std { +template <typename T> +class vector { +public: + void assign(int __n, const T &__val); +}; +template<typename T> +void swap(T& __a, T& __b); +} // namespace std +namespace ignore_std_functions { +void test(int a, int b) { + std::vector<int> s; + // verify the check is not fired on std functions. + s.assign(1, /*value=*/2); + std::swap(a, /*num=*/b); +} +} // namespace ignore_std_functions Index: clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp +++ clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp @@ -19,6 +19,13 @@ namespace clang { namespace tidy { namespace bugprone { +namespace { +AST_MATCHER(Decl, isFromStdNamespace) { + if (const auto *D = Node.getDeclContext()->getEnclosingNamespaceContext()) + return D->isStdNamespace(); + return false; +} +} // namespace ArgumentCommentCheck::ArgumentCommentCheck(StringRef Name, ClangTidyContext *Context) @@ -54,10 +61,18 @@ // don't check them against NewCallback's parameter names. // FIXME: Make this configurable. unless(hasDeclaration(functionDecl( - hasAnyName("NewCallback", "NewPermanentCallback"))))) + hasAnyName("NewCallback", "NewPermanentCallback")))), + // Ignore APIs from the standard library, since their names are + // 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()))) .bind("expr"), this); - Finder->addMatcher(cxxConstructExpr().bind("expr"), this); } static std::vector<std::pair<SourceLocation, StringRef>>
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp +++ clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp @@ -115,3 +115,22 @@ // CHECK-NOTES: [[@LINE-3]]:13: note: 'xxx' declared here // CHECK-FIXES: void g() { f6(/*xxy=*/0, 0); } } + + +namespace std { +template <typename T> +class vector { +public: + void assign(int __n, const T &__val); +}; +template<typename T> +void swap(T& __a, T& __b); +} // namespace std +namespace ignore_std_functions { +void test(int a, int b) { + std::vector<int> s; + // verify the check is not fired on std functions. + s.assign(1, /*value=*/2); + std::swap(a, /*num=*/b); +} +} // namespace ignore_std_functions Index: clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp +++ clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp @@ -19,6 +19,13 @@ namespace clang { namespace tidy { namespace bugprone { +namespace { +AST_MATCHER(Decl, isFromStdNamespace) { + if (const auto *D = Node.getDeclContext()->getEnclosingNamespaceContext()) + return D->isStdNamespace(); + return false; +} +} // namespace ArgumentCommentCheck::ArgumentCommentCheck(StringRef Name, ClangTidyContext *Context) @@ -54,10 +61,18 @@ // don't check them against NewCallback's parameter names. // FIXME: Make this configurable. unless(hasDeclaration(functionDecl( - hasAnyName("NewCallback", "NewPermanentCallback"))))) + hasAnyName("NewCallback", "NewPermanentCallback")))), + // Ignore APIs from the standard library, since their names are + // 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()))) .bind("expr"), this); - Finder->addMatcher(cxxConstructExpr().bind("expr"), this); } static std::vector<std::pair<SourceLocation, StringRef>>
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits