P4021R1 — compile_assert - an assert that evaluates at compile time
Jonathan Grant
EWGI
Revisions R2Apr 2026R1Apr 2026R0Feb 2026
It is used for bounds checking, avoiding nullptr dereference, parameter validation and data validation at compile time. It only works in Optimized enabled compilers. All three major compilers (GCC, Clang, MSVC) are supported with a sample implementation. The GCC/Clang implementation use the a function error attribute: