C++ Logo

std-proposals

Advanced search

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

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Thu, 19 Feb 2026 17:36:54 +0200
On Thu, 19 Feb 2026 at 17:33, Jonathan Wakely via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> void f(int* p) {
> compiler_assert(p != nullptr);
> }
>
> Even with optimizations turned up to maximum, this will always be ill-formed.

Sure. And then

void f(int* p) {
  some_mandatory_runtime_assert(p != nullptr);
  compiler_assert(p != nullptr);
}

can make it well-formed.

Received on 2026-02-19 15:37:07