File tree Expand file tree Collapse file tree 4 files changed +32
-9
lines changed Expand file tree Collapse file tree 4 files changed +32
-9
lines changed Original file line number Diff line number Diff line change @@ -20,10 +20,12 @@ namespace clang {
20
20
namespace tidy {
21
21
namespace bugprone {
22
22
namespace {
23
- AST_MATCHER (Decl, isFromStdNamespace ) {
23
+ AST_MATCHER (Decl, isFromStdNamespaceOrSystemHeader ) {
24
24
if (const auto *D = Node.getDeclContext ()->getEnclosingNamespaceContext ())
25
- return D->isStdNamespace ();
26
- return false ;
25
+ if (D->isStdNamespace ())
26
+ return true ;
27
+ return Node.getASTContext ().getSourceManager ().isInSystemHeader (
28
+ Node.getLocation ());
27
29
}
28
30
} // namespace
29
31
@@ -66,13 +68,13 @@ void ArgumentCommentCheck::registerMatchers(MatchFinder *Finder) {
66
68
// not specified by the standard, and standard library
67
69
// implementations in practice have to use reserved names to
68
70
// avoid conflicts with same-named macros.
69
- unless (hasDeclaration (isFromStdNamespace ())))
70
- .bind (" expr" ),
71
- this );
72
- Finder->addMatcher (
73
- cxxConstructExpr (unless (hasDeclaration (isFromStdNamespace ())))
71
+ unless (hasDeclaration (isFromStdNamespaceOrSystemHeader ())))
74
72
.bind (" expr" ),
75
73
this );
74
+ Finder->addMatcher (cxxConstructExpr (unless (hasDeclaration (
75
+ isFromStdNamespaceOrSystemHeader ())))
76
+ .bind (" expr" ),
77
+ this );
76
78
}
77
79
78
80
static std::vector<std::pair<SourceLocation, StringRef>>
Original file line number Diff line number Diff line change
1
+ void my_header_function (int arg );
Original file line number Diff line number Diff line change
1
+ #pragma clang system_header
2
+
3
+ void my_system_header_function (int arg );
Original file line number Diff line number Diff line change 1
- // RUN: %check_clang_tidy %s bugprone-argument-comment %t
1
+ // RUN: %check_clang_tidy %s bugprone-argument-comment %t -- -- -I %S/Inputs/bugprone-argument-comment
2
2
3
3
// FIXME: clang-tidy should provide a -verify mode to make writing these checks
4
4
// easier and more accurate.
@@ -134,3 +134,20 @@ void test(int a, int b) {
134
134
std::swap (a, /* num=*/ b);
135
135
}
136
136
} // namespace ignore_std_functions
137
+
138
+ namespace regular_header {
139
+ #include " header-with-decl.h"
140
+ void test () {
141
+ my_header_function (/* not_arg=*/ 1 );
142
+ // CHECK-NOTES: [[@LINE-1]]:22: warning: argument name 'not_arg' in comment does not match parameter name 'arg'
143
+ // CHECK-NOTES: header-with-decl.h:1:29: note: 'arg' declared here
144
+ // CHECK-FIXES: my_header_function(/*not_arg=*/1);
145
+ }
146
+ } // namespace regular_header
147
+
148
+ namespace system_header {
149
+ #include " system-header-with-decl.h"
150
+ void test () {
151
+ my_system_header_function (/* not_arg=*/ 1 );
152
+ }
153
+ } // namespace system_header
You can’t perform that action at this time.
0 commit comments