Linux command
clang-check 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Run syntax checking
clang-check [source.cpp]
Check with specific compiler flags
clang-check [source.cpp] -- -std=c++17 -I[/include/path]
Dump the AST
clang-check -ast-dump [source.cpp]
Example
clang-check -ast-dump -ast-dump-filter [functionName] [source.cpp]
Analyze using a compilation database
clang-check -p [build/] [source.cpp]
Example
clang-check -fixit [source.cpp]
说明
clang-check is a tool that combines the LibTooling framework for running a Clang tool with basic Clang diagnostics. It performs syntax checking, type checking, and can dump or pretty-print the Abstract Syntax Tree (AST) for inspection. It can also apply fix-it suggestions automatically. Part of the LLVM/Clang toolchain, it is useful for quick validation and AST exploration without full compilation.
参数
- -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.
- -ast-dump-filter _name_
- Filter AST dump/print to only nodes with a matching qualified name.
- -fixit
- Apply fix-it advice to the input source.
- --extra-arg _arg_
- Additional argument to append to the compiler command line.
- --extra-arg-before _arg_
- Additional argument to prepend to the compiler command line.
FAQ
What is the clang-check command used for?
clang-check is a tool that combines the LibTooling framework for running a Clang tool with basic Clang diagnostics. It performs syntax checking, type checking, and can dump or pretty-print the Abstract Syntax Tree (AST) for inspection. It can also apply fix-it suggestions automatically. Part of the LLVM/Clang toolchain, it is useful for quick validation and AST exploration without full compilation.
How do I run a basic clang-check example?
Run `clang-check [source.cpp]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -p _path_ do in clang-check?
Path to compilation database (compile_commands.json).