void MyChecker::checkPostStmt(const CallExpr *CE, CheckerContext &C) const { if (CE->getDirectCallee()->getName() == "my_function") { C.emitWarning("my_function is called!"); } }
void MyChecker::checkPreStmt(const IfStmt *S, CheckerContext &C) const { if (S->getConditionVariable()) { C.emitError(S, "if statement with initialization"); } }This example demonstrates how to use CheckerContext to check for a specific kind of statement. In this case, the checkPreStmt method is called before a statement is executed, and if the statement is an if statement with initialization, an error is emitted. Package/library: clang-analyzer