void MyChecker::checkCallExpr(const CallExpr *CE, CheckerContext &C) const { if (CE->getNumArgs() < 2) { PathDiagnosticLocation CELoc = PathDiagnosticLocation::createBegin(CE, C.getSourceManager(), C.getASTContext()); C.generateNonFatalErrorNode(CE, "Too few arguments in function call", CELoc); } }
void MyChecker::checkMacroExpansion(const Token &MacroNameTok, const MacroDirective *MD, SourceRange Range, CheckerContext &C) const { if (MacroNameTok.getIdentifierInfo()->getName() == "MY_MACRO") { PathDiagnosticLocation MacroLoc = PathDiagnosticLocation::createBegin(MacroNameTok, C.getSourceManager(), C.getASTContext()); C.generateNonFatalErrorNode(MacroNameTok.getLocation(), Range.getEnd(), "MY_MACRO should not be used", MacroLoc); } }In this example, we check if a macro with the name "MY_MACRO" is used. If it is, we use generateNonFatalErrorNode to create a diagnostic node with the message "MY_MACRO should not be used". Based on the syntax it looks like the CheckerContext and generateNonFatalErrorNode are part of the Clang Static Analyzer library.