[PATCH 1/2 v2] c++: Implement P1494 and P3641 Partial program correctness [PR119060].

Michael Matz matz@suse.de
Tue Sep 9 16:15:34 GMT 2025


Hello,

On Tue, 9 Sep 2025, Ville Voutilainen wrote:

> > But it would also be an invalid transformation of the compiler.  So I
> > can't quite see the worry.  The second check ("*p > 5") is conditional on
> > the first one:
> >
> >   if (!p)
> >     fail()
> >   if (*p > 5)
> >     fail2()
> 
> The fail() can fall through when the contracts are evaluated in the
> "observe" evaluation mode.
> In that case it's not an actual "fail", it will call the contract
> violation handler and return from that.

I see.  So my (b) case, independend contracts (as far is their evaluation 
is concerned).  Given these two contracts and that evaluation mode, how 
would the segfault in evaluating the second contract be avoided?

> And then the concern is that that call may be completely elided because 
> what follows is UB in the form of the pointer dereference.

I don't see how a correct compiler could eliminate the call to fail() if 
it contains any interesting side-effect, because most interesting 
side-effects (here: i/o) always have the potential of either _exit(0) or 
endlessly looping, and hence not actually reaching the UB.

If, on the contrary, fail() doesn't contain any side-effects, then not 
even calling it seems to be unobservable to me.  So, which side-effects 
that aren't really side-effects do you want to preserve within fail() with 
the help of the proposed extension?


Ciao,
Michael.


More information about the Libstdc++ mailing list