On 02/11/2026 11:28, Jonathan Grant wrote:
On 26/10/2026 20:18, Ion Gaztañaga wrote:
El 25/10/2026 a las 13:52, Jonathan Grant via Boost escribió:
Hello
I'd like to introduce my P4021 - compile_assert, compile-time diagnostics for expressions that can be proven at compile time. ie they are not const, constexpr, consteval.
https://isocpp.org/files/papers/P4021R2.pdf
There's a github repo with a testsuite, showing lots of simple examples. It's a useful tool to detect issues at compile time, like nullptr dereferences, divide by zero, array subscript errors.
It diagnoses invariants that are proven false, as well as invariants that are not-proven. Helps make software more robust. Handy for Functional Safety. It does this by identifying code that is reachable, but should not be.
Could something like this be added to Boost?
I also hope tools like Claude could utilise compile_assert() to evaluate open source software.
Regards Jonathan
Hi Julien,
How was your paper received in WG14? If I understand this correctly, we are relying on compiler's ability to prove the assertion, so I guess that when some limits are passed the compiler won't be able to prove it and the code won't compiler?
Best,
Ion
Hi Ion,
WG14 and WG21 were not overly positive, similar challenges in standardising, primarily because it relies on control-flow analysis, which the languages do not define.
The sample implementation uses [[attribute(error)]] or [[attribute(warning)]] to generate the diagnostic. It could also use [[deprecated]], allowing programmers to review the diagnostic and decide how to proceed based on the diagnostic.
There is a testsuite containing examples: https://github.com/jonnygrant/compile_assert/tree/main/testsuite
ie, it can diagnose situations where an array subscript may not always be within bounds.
Google's research showed such checks cost additional 0.3% CPU. For functional safety applications, this seems a worthwhile trade-off, particularly where performance is not the primary concern. Array subscript bounds checking has been available by default in programming languages since the 1980 and before.
Would this be something worth considering for Boost?
Regards Jonathan
ps. In your software, do you have any use-cases where you wish to avoid a zero ever getting through and causing divide-by-zero SIGFPE, a NaN, or nullptr dereference SIGSEGV? Array subscript may cause SIGSEGV as well. Regards Jonathan