Date: Sat, 28 Feb 2026 00:15:51 +0000
On 22/02/2026 13:32, Alejandro Colomar wrote:
> 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.
It's a good point Alejandro, programmers can make whichever pattern they wish once they have a simple compile time assert.
>> 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.
I've added your compiler_assert suggestion to my draft edit, I'm definitely keen to discuss and choose the most appropriate name.
You've probably heard this story - but I'll share it:
When Dennis Richie was asked what he would change about UNIX if he could do it again, it he said he would add an 'e' on creat(). I'll have a good think about the suggestion to add 'r' in compile_assert()!
I was also thinking about a few keywords
constraint()
insist()
constexpr_assert() [I avoided consteval_assert as I think consteval is meant to be 100% certain, constexpr is subjective I believe]
BTW, I have got compiler_assert() for MSVC in my latest edit, and shows how to get file and line info output via missing symbol name at link time. We could use the same approach on any compiler.
Regards
Jonathan
> 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.
It's a good point Alejandro, programmers can make whichever pattern they wish once they have a simple compile time assert.
>> 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.
I've added your compiler_assert suggestion to my draft edit, I'm definitely keen to discuss and choose the most appropriate name.
You've probably heard this story - but I'll share it:
When Dennis Richie was asked what he would change about UNIX if he could do it again, it he said he would add an 'e' on creat(). I'll have a good think about the suggestion to add 'r' in compile_assert()!
I was also thinking about a few keywords
constraint()
insist()
constexpr_assert() [I avoided consteval_assert as I think consteval is meant to be 100% certain, constexpr is subjective I believe]
BTW, I have got compiler_assert() for MSVC in my latest edit, and shows how to get file and line info output via missing symbol name at link time. We could use the same approach on any compiler.
Regards
Jonathan
Received on 2026-02-28 00:15:55
