void MyChecker::checkAST(const MatchFinder::MatchResult &Result) { CheckerContext &Context = *Result.Context; ASTContext &ASTCtx = Context.getASTContext(); if (ASTCtx.getLangOpts().CPlusPlus) { // This translation unit is C++ // Perform C++ specific checks } else { // This translation unit is not C++ // Perform non-C++ checks } }
void MyChecker::check(const MatchFinder::MatchResult &Result) { CheckerContext &Context = *Result.Context; ASTContext &ASTCtx = Context.getASTContext(); auto M = Result.Nodes.getNodeAsIn this example, we check whether a statement has more than one parent in the AST. If it does, we emit an error message using the `emitError` function provided by the checker context. Package library: Clang Static Analyzer, which is a standalone tool that can be used to analyze C and C++ code, among others.("my_stmt"); if (M && ASTCtx.getParents(*M).size() > 1) { // The statement has more than one parent Context.emitError(M, "Statement has multiple parents"); } }