C++ Logo

sg15

Advanced search

Re: [isocpp-sg15] [isocpp-ext] A small request re the "new UB" concern, please

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Fri, 24 Oct 2025 01:09:46 +0300
On Fri, 24 Oct 2025 at 01:05, Oliver Hunt via Ext <ext_at_[hidden]> wrote:
> Is the issue that in observe mode in this case that these contract assertions turn into something like (pseudo code)
>
> if (p != nullptr) report();
> if (!p->foo()) report();
>
> And the compiler is permitted to assume that `p->foo()` means that `p` is nonnull and back propagate that assumption forward or backwards through time?
>
> I had thought that the observable checkpoints were intended to act as a fence that prevented such optimization?

The issue isn't such an optimization, but that the second check has
UB. It won't propagate backwards, but it's still UB.

Received on 2025-10-23 22:10:00