LinuxCommandLibrary

clang-check

Clang-based static analysis and AST inspection tool

TLDR

Run static analysis on a source file
$ clang-check [source.cpp]
copy
Check with specific compiler flags
$ clang-check [source.cpp] -- [--std=c++17] [-I/include/path]
copy
Run analysis with AST dump
$ clang-check -ast-dump [source.cpp]
copy
Analyze using compilation database
$ clang-check -p [build/] [source.cpp]
copy

SYNOPSIS

clang-check [options] source-files [--] [compiler-options]

DESCRIPTION

clang-check is a tool for running Clang-based static analysis on C/C++ source files. It performs syntax checking, type checking, and can dump the Abstract Syntax Tree (AST) for inspection.
Part of the LLVM/Clang toolchain, it's useful for quick validation and AST exploration without full compilation.

PARAMETERS

-p path

Path to compilation database (compile_commands.json).
-ast-dump
Dump the AST to stdout.
-ast-list
List AST nodes.
-ast-print
Pretty-print the AST.
-analyze
Run static analysis.

CAVEATS

Requires Clang to be installed. For project-wide analysis with correct include paths, use a compilation database (compile_commands.json).

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard