[clang] [clang-tools-extra] [clang-tidy] Avoid matching nodes in system headers (PR #151035)
Carlos Galvez via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 3 11:20:33 PDT 2025
================
@@ -1336,6 +1336,44 @@ class MatchASTVisitor : public RecursiveASTVisitor<MatchASTVisitor>,
return false;
}
+ template <typename T> static SourceLocation getNodeLocation(const T &Node) {
+ return Node.getBeginLoc();
+ }
+
+ static SourceLocation getNodeLocation(const QualType &Node) { return {}; }
+
+ static SourceLocation getNodeLocation(const NestedNameSpecifier &Node) {
+ return {};
+ }
+
+ static SourceLocation getNodeLocation(const CXXCtorInitializer &Node) {
+ return Node.getSourceLocation();
+ }
+
+ static SourceLocation getNodeLocation(const TemplateArgumentLoc &Node) {
+ return Node.getLocation();
+ }
+
+ static SourceLocation getNodeLocation(const Attr &Node) {
+ return Node.getLocation();
+ }
+
+ bool isInSystemHeader(const SourceLocation &Loc) {
+ const SourceManager &SM = getASTContext().getSourceManager();
+ return SM.isInSystemHeader(Loc);
+ }
+
+ template <typename T> bool shouldSkipNode(const T &Node) {
+ if constexpr (std::is_pointer_v<T>)
+ return (Node == nullptr) || shouldSkipNode(*Node);
+ else {
+ if (Options.IgnoreSystemHeaders &&
+ isInSystemHeader(getNodeLocation(Node)))
+ return true;
+ return false;
----------------
carlosgalvezp wrote:
This suggestion will likely need to be undone soon, by the above-mentioned PR regarding modules, like:
```cpp
if (SystemHeaders)
{
return true;
}
else if (Modules)
{
return true;
}
return false;
```
https://github.com/llvm/llvm-project/pull/151035
More information about the cfe-commits
mailing list