Skip to main content
ai-slop/cpp-define-constantmanual fix

#define constant.

`#define MAX_RETRIES 5` in C++: a macro used as a constant. It has no type, ignores scope, and is gone before the debugger sees it.

Flagged shape and clean shape.

Each example shows the exact code shape the rule is looking for, then the smallest version that keeps the intent without hiding risk or adding noise.

cpp-define-constant.cpp
✗ Flagged
#define MAX_RETRIES 5
#define DEFAULT_TIMEOUT_MS 3000
#define SERVICE_NAME "billing"
Why this trips

Deterministic line match: flags `#define` of an upper-case name whose value starts with a digit, quote, minus sign, or parenthesis, in C++ files.

cpp-define-constant.cpp
✓ Clean
namespace billing {
constexpr int kMaxRetries = 5;
constexpr std::chrono::milliseconds kDefaultTimeout{3000};
constexpr std::string_view kServiceName = "billing";
}
What changed

Use `constexpr` (or `const`) with an explicit type, inside a namespace or class if it belongs to one.

Agents copy constant definitions from C-era examples, where macros were the only option.

How this rule is justified.

Rule id

ai-slop/cpp-define-constant

Enforcing engine

ai-slop

Detector strategy

Deterministic line match: flags `#define` of an upper-case name whose value starts with a digit, quote, minus sign, or parenthesis, in C++ files.

Legitimate code that is NOT flagged

`.c` and `.h` files, include guards and other value-less defines, and function-like macros such as `#define MAX(a, b)` are not flagged.

Evidence

Part of aislop's C/C++ rule set. C/C++ support, including C/C++-specific AI-slop rules, arrived in aislop v0.14.1.