这里可以使用clang-query这个工具来验证matcher是否正确。 这里不再赘述, 可以参考clang的官方文档,接下来,我们来写我们的matcher,注册到registerMatchers中 const auto opnewDecl = cxxMethodDecl(hasName("operator new")).bind("noopnew"); void EigenhasoperatornewCheck::registerMatchers(MatchFinder *Finder) {...
bin/clang-tidy --checks='bugprone-multi-pointer' ../../test/testASTMatcher.cpp 来进行检测 可以得到效果:
Clang-Tidy的功能主要基于两个组件: 语法树匹配器(AST Matcher):Clang-Tidy使用语法树匹配器根据给定的模式匹配源代码中的特定结构。这使得开发者可以定义自定义规则并根据需求对代码进行静态分析。 固定(Fixes):Clang-Tidy能够自动进行一些基本的代码改进操作,例如插入缺失的关键字、删除无用的代码片段等。这些固定可以...
根据你的操作系统,这可能涉及到更新PATH环境变量或者其他类似的配置。...指定Clang-Tidy的完整路径:如果你知道Clang-Tidy的完整路径,可以在执行Clang-Tidy命令时指定完整的路径。...Clang-Tidy的功能主要基于两个组件:语法树匹配器(AST Matcher):Clang-Tidy使用语法树匹配器根据给定的模式匹配源代码中的特定结构。
clang::ast_matchers::internal::Matcher<Expr>, InnerMatcher) { if (const Expr *CookedLiteral = Node.getCookedLiteral()) { const UserDefinedLiteral::LiteralOperatorKind LOK = Node.getLiteralOperatorKind(); if (LOK == UserDefinedLiteral::LOK_Template || LOK == UserDefinedLiteral::LOK_Raw) ...
void check(const ast_matchers::MatchFinder::MatchResult &Result) final;--protected:bool isLanguageVersionSupported(const LangOptions &LO) const final {-return LO.CPlusPlus20;+return LO.CPlusPlus;} };diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst...
Another change I have made is that I renamed the binding fromxtoaddAwesomePrefix. This is notable because it uses verbs to describe what should be done with the matches. It should be clear from reading matcher bindings what the result of invoking the fix is to be. Binding names ...
语法树匹配器(AST Matcher):Clang-Tidy使用语法树匹配器根据给定的模式匹配源代码中的特定结构。这使得开发者可以定义自定义规则并根据需求对代码进行静态分析。 固定(Fixes):Clang-Tidy能够自动进行一些基本的代码改进操作,例如插入缺失的关键字、删除无用的代码片段等。这些固定可以帮助开发者快速修复发现的问题,提高代...
This post is part of a three-part series about using the Clang AST Matchers to mechanically refactor C++ code. In thelast post, we ensured that the code is at least buildable with Clang. While that part was only interesting to those whose code was not yet building with Clang, the rest...
auto StringType = hasUnqualifiedDesugaredType(recordType(hasDeclaration(cxxRecordDecl( hasName("::std::basic_string"))); auto PrintCall = hasName("::fmt::print"); StatementMatcher CStrMatcher = traverse( TK_AsIs, callExpr(callee(functionDecl(PrintCall)), hasAnyArgument(cxxMemberCallExpr( callee...