A clang-tidy check that enforces $macros to visually separate them from regular identifiers.
With this check enabled, you will get warnings if you try to define a macro without prefixing its name with a $. Likewise, you will get a warning if you use a regular identifier that starts with $.
- CMake 3.20+
- Ninja
- Clang/Clang++
- Pre-built LLVM and Clang
python build-plugin.pyThis configures and builds the plugin, installing it to ./install/lib/dollar_macros.so.
Note: Requires LLVM to be pre-built at ./llvm-project/build/ (or specify with --llvm-build).
# Configure
cmake -B build -S . \
-DLLVM_SRC_DIR=./llvm-project \
-DLLVM_BUILD_DIR=./llvm-project/build \
-DCMAKE_INSTALL_PREFIX=./install
# Build
ninja -C build
# Install
ninja -C build installpython build-plugin.py \
--llvm-src /path/to/llvm-project \
--llvm-build /path/to/llvm-project/build \
--install-dir ./installAdd the check to your .clang-tidy configuration:
Checks: 'dollar-macro'
CheckOptions:
- key: dollar-macro.ignore-prefixes
value: 'SOMELIB_,BOOST_'Use ignore-prefixes to permit additional (comma-separated) prefixes:
SOMELIB_- Allow macros that use theSOMELIB_prefixBOOST_- Allow macros that use Boost'sBOOST_prefix
Reserved identifiers and system header macros are automatically excluded.
See example/.clang-tidy for a complete configuration example.
Run clang-tidy with the plugin:
clang-tidy --load=/path/to/dollar_macros.so -checks='dollar-macro' file.cppThe test/ directory contains test cases demonstrating the check's behavior:
lit test/