P4021R0 — compile_assert
(6 items)
EWGI, EWG
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.
- §2, Motivation and Scope (page 2) — Macro definition uses parameter names (expression, message) in the #if branch but (condition, description) in the #else branch; parameters should be consistent across both branches. [1]
- §1, Introduction (page 1) — "Although" introduces a subordinate clause with no main clause, producing a sentence fragment. [2]
- Pages 7-8 — Two different sections are both numbered 10; Acknowledgements should be renumbered and subsequent sections adjusted. [3]
- Page 8 — Two different sections are both numbered 11, a consequence of the duplicate section 10 above. [4]
- §6, Interaction With Existing Features (page 5) — "costexpr" is a misspelling of "constexpr." [1] [5]
- §9, Examples (page 7) — Filename "main12. c" contains a spurious space before the extension; should be "main12.c" to match all other examples. [6]
References — Anthropic Citations API
[1]
"Interaction With Existing Features No interaction with costexpr, concepts, templates, modules. "
"Interaction With Existing Features No interaction with costexpr, concepts, templates, modules. "
[2]
"10. Notes" (page 7) and "10. Acknowledgements" (page 8)"
"10. Notes" (page 7) and "10. Acknowledgements" (page 8)"
[3]
"11. References" and "11. External resources""
"11. References" and "11. External resources""
[4]
"Although I appreciate compile_assert finding issues means programmers will be required to add defensive code."
"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)`."
"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"
"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.
Provenance: All references are machine-verified character positions from the Anthropic Citations API — deterministic, exact substrings, not model-generated quotes.