Date: Wed, 11 Mar 2026 03:42:24 +0000
On 20/02/2026 11:45, Jonathan Wakely via Std-Proposals wrote:
>
>
> On Fri, 20 Feb 2026 at 11:33, Bjorn Reese via Std-Proposals <std-proposals_at_[hidden] <mailto:std-proposals_at_[hidden]>> wrote:
>
> On 2/19/26 15:59, Alejandro Colomar via Std-Proposals wrote:
>
> > A viable GCC implementation would be
>
> Isn't it sufficient and portable to call assert() in a constexpr
> context? For example
>
> constexpr void compiler_assert(bool condition) {
> assert(condition);
> }
>
> I am aware that the above does not generate a useful error message, but
> that can be remedied.
>
>
> No, that requires the condition to be a constant expression. The proposed feature only requires it to be a "compile-time constant" after compiler optimizations, which is a weaker requirement.
>
> int i = 1;
> static_assert(1); // not a constant expression
> compile_assert(1); // might be constant, with optimization
>
> Whether something is a constant expression is formally defined by the C++ standard.
>
> Whether something is a compile-time constant depends on the compiler performing value propagation, common subexpression elimination, etc.
>
That's a good point, as soon as I add noinline on a get_index() it can't be checked by compile_assert(). Maybe that is fine, the programmer has set noinline, so it's a known limitation, better not to check the result of such functions in a post condition.
On a particular build I might like to ignore the noinline attributes to see if any expressions fail.
If I add -Dnoinline that should be enough to turn them off for that moment. It will compile out.
While I remember, I think you gave me the suggestion back in 2023 to use a function with __attribute__ error to get my compile_assert() to stop the build on gcc-help. Without your suggestion I would not have been able to fix issues over these past years using the approach.
Regards
Jonathan
>
>
> On Fri, 20 Feb 2026 at 11:33, Bjorn Reese via Std-Proposals <std-proposals_at_[hidden] <mailto:std-proposals_at_[hidden]>> wrote:
>
> On 2/19/26 15:59, Alejandro Colomar via Std-Proposals wrote:
>
> > A viable GCC implementation would be
>
> Isn't it sufficient and portable to call assert() in a constexpr
> context? For example
>
> constexpr void compiler_assert(bool condition) {
> assert(condition);
> }
>
> I am aware that the above does not generate a useful error message, but
> that can be remedied.
>
>
> No, that requires the condition to be a constant expression. The proposed feature only requires it to be a "compile-time constant" after compiler optimizations, which is a weaker requirement.
>
> int i = 1;
> static_assert(1); // not a constant expression
> compile_assert(1); // might be constant, with optimization
>
> Whether something is a constant expression is formally defined by the C++ standard.
>
> Whether something is a compile-time constant depends on the compiler performing value propagation, common subexpression elimination, etc.
>
That's a good point, as soon as I add noinline on a get_index() it can't be checked by compile_assert(). Maybe that is fine, the programmer has set noinline, so it's a known limitation, better not to check the result of such functions in a post condition.
On a particular build I might like to ignore the noinline attributes to see if any expressions fail.
If I add -Dnoinline that should be enough to turn them off for that moment. It will compile out.
While I remember, I think you gave me the suggestion back in 2023 to use a function with __attribute__ error to get my compile_assert() to stop the build on gcc-help. Without your suggestion I would not have been able to fix issues over these past years using the approach.
Regards
Jonathan
Received on 2026-03-11 03:42:31
