cpp-const-correctness
C++ Const Correctness
Use this skill to resolve clang-tidy misc-const-correctness findings: local variables (value, reference, and - when enabled - pointer locals) that are never modified after initialization and could therefore be declared const. The goal is a fast, correct, mechanical fix that does not introduce a regression or a new tidy warning.
The check enforces ES.25: declare an object const unless you intend to modify it. The analysis is type-based only — it flags a local as const-able when no expression in scope can mutate it. It analyzes only local variables: it does not look at function parameters, data members, or globals.
UTILITY SKILL. INVOKES: read-only file access for supplied targets; no other tools or skills. FOR SINGLE OPERATIONS: use to fix a single flagged declaration or sweep a file for missing const.
Scope
- Use this skill for local variables only: local value variables (
int i = 42;→int const i = 42;), local references (int& r = i;→int const& r = i;), and - whenWarnPointersAsValuesis enabled - local pointers that are never reseated (T* p→T* const p). - Apply it whenever clang-tidy emits
misc-const-correctness. The check is most useful when the project gates themisc-*group as warnings-as-errors, so a missingconston a flagged local fails the build. - Keep the fix behavior-preserving: adding
constmust not change overload resolution, template instantiation, move eligibility, or API/ABI.