Date: Sun, 22 Feb 2026 14:32:53 +0100
Hi Jonathan,
On 2026-02-22T12:35:15+0000, Jonathan Wakely via Std-Proposals wrote:
> Yes, I think "make it ill-formed at compile-time when optimizing, otherwise
> add a runtime assertion" would be something people want to do.
>
> With the current proposal, that's awkward. You would need to do:
>
> #ifdef __OPTIMIZING__ && __ENABLE_COMPILE_ASSERT__
> compile_assert(cond);
> #else
> assert(cond);
> #endif
>
> or wrap that into your own macro. But that depends on a non-standard macro
> which is compiler-dependent. It would be easier if the feature defined
> something that you could check to see if the compile_assert is actually
> enabled.
I think what you called awkward would actually be great. Programmers
would be free to choose the behavior they want from first principles.
compiler_assert() would be a first principle. Feature test macros for
these things are a higher level feature.
> Also, the more I look at code examples using this, the less I like the
> name. It didn't tell me what it does. All assertions are compiled, what is
> a "compile assert"? Assert that something compiles, i.e. is syntactically
> valid? That's what a requires expression does, but it's not what this does.
I call this compiler_assert(), which I think is a better name.
Have a lovely day!
Alex
On 2026-02-22T12:35:15+0000, Jonathan Wakely via Std-Proposals wrote:
> Yes, I think "make it ill-formed at compile-time when optimizing, otherwise
> add a runtime assertion" would be something people want to do.
>
> With the current proposal, that's awkward. You would need to do:
>
> #ifdef __OPTIMIZING__ && __ENABLE_COMPILE_ASSERT__
> compile_assert(cond);
> #else
> assert(cond);
> #endif
>
> or wrap that into your own macro. But that depends on a non-standard macro
> which is compiler-dependent. It would be easier if the feature defined
> something that you could check to see if the compile_assert is actually
> enabled.
I think what you called awkward would actually be great. Programmers
would be free to choose the behavior they want from first principles.
compiler_assert() would be a first principle. Feature test macros for
these things are a higher level feature.
> Also, the more I look at code examples using this, the less I like the
> name. It didn't tell me what it does. All assertions are compiled, what is
> a "compile assert"? Assert that something compiles, i.e. is syntactically
> valid? That's what a requires expression does, but it's not what this does.
I call this compiler_assert(), which I think is a better name.
Have a lovely day!
Alex
-- <https://www.alejandro-colomar.es>
Received on 2026-02-22 13:33:12
