On Thu, 19 Feb 2026 at 17:33, Jonathan Wakely via Std-Proposals
<std-proposals@lists.isocpp.org> 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.
Or just:
[[assume(p)]];
compiler_assert(p != nullptr);
Which can (sometimes, depending on optimizations) also work if the assume is in the caller of f, but only if all calls to f are inlined.
[[gnu::always_inline]]
inline void f(int* p) {
compiler_assert(p != nullptr);
}
void g(int p)
{
f(&p); // ok, address is non-null
}
void h(int* p)
{
[[assume(p)]];
f(p); // ok, address assumed non-null
}