C++ Logo

std-proposals

Advanced search

Re: [std-proposals] compile_assert() a static assert that fires at compile time, not runtime.

From: Jan Schultke <janschultke_at_[hidden]>
Date: Thu, 19 Feb 2026 16:58:42 +0100
>
> It also doesn't work at all, because next to no user of this facility
> wants the contract evaluation semantic configuration to turn this
> assert completely off.
>

Maybe you don't want it, but it sounds a lot like OP wants something along
those lines. As Jonathan said, when __OPTIMIZE__ is not defined, all the
compile_asserts go away.

That's exactly the kind of global configuration that I'm thinking of. Of
course, you may want to make decisions differently for different contract
assertions/preconditions, and there are proposals that allow for that.


> And they certainly don't want the act of turning off runtime checks to
> also turn off all compile-time checks.
>

But people doing that is the status quo. Ignore semantic with contracts
gets rid of any runtime check, and also offers no compile-time check (other
than static analysis in the future). The new "proof" semantic would allow
you to turn off runtime checks and turn them into compile-time checks.

Of course, once again, there is still the issue of granularity; you can
only switch globally, and that's presumably going to be fixed in C++29.

Received on 2026-02-19 15:58:55