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
// 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>>
-// 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.
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