P4021R0 — compile_assert (6 items) EWGI, EWG
Jonathan Grant
This paper proposes compile_assert(expression, message), a new C++ keyword for enforcing assertions at compile time within ordinary (non-constexpr) functions. Unlike static_assert, which requires constant expressions, compile_assert relies on the compiler's optimizer and control-flow analysis to determine whether an assertion's failure path is reachable, making the program ill-formed if such a path exists. The feature has zero runtime cost, produces diagnostics with file and line information, and has been demonstrated via a GCC-based macro implementation using __attribute__((error)) since 2023.

References — Anthropic Citations API

[1]
"Interaction With Existing Features No interaction with costexpr, concepts, templates, modules. "
[2]
"10. Notes" (page 7) and "10. Acknowledgements" (page 8)"
[3]
"11. References" and "11. External resources""
[4]
"Although I appreciate compile_assert finding issues means programmers will be required to add defensive code."
[5]
"The active branch defines `#define compile_assert(expression, message)` while the inactive branch defines `#define compile_assert(condition, description)`."
[6]
"main12. c - demonstrate compile_assert checking an offset resolved to a pointer is within the range bounds of a buffer"
Summary: P4021R0 proposes compile_assert, a new compile-time assertion mechanism intended to surface diagnostic messages during translation. The paper covers motivation, interaction with existing features, and provides usage examples across several translation units.
Pipeline: Discovery (Anthropic Opus + Citations API) → Verification Gate (OpenRouter Opus) → Report Writer (OpenRouter Opus)
Provenance: All references are machine-verified character positions from the Anthropic Citations API — deterministic, exact substrings, not model-generated quotes.