C++ Logo

sg15

Advanced search

Re: [isocpp-sg15] [isocpp-sg21] P3835 -- Different contract checking for different libraries

From: Daniela Engert <dani_at_[hidden]>
Date: Fri, 17 Oct 2025 12:26:16 +0200 (CEST)
> Harald Achitz via SG15 <sg15_at_[hidden]> hat am 17.10.2025 12:03 CEST geschrieben:
> On the internet I saw someone saying
>
> void fun(Foo* ptr) pre (ptr!=nullpter), pre(ptr->hasData()) { ... }
>
> might be a problem (for the second pre) and should be written like this
>
> void fun(Foo* ptr) pre (ptr!=nullpter && ptr->hasData()){ ... }
 
> is that true?

It is. Otherwise you'd get UB with 'observe' contract evaluation semantics.

Thanks
Dani

>
> Thanks, Harald
>
>
> On 2025-10-17 10:43, Ville Voutilainen wrote:
> > On Fri, 17 Oct 2025 at 11:22, Harald Achitz via SG21
> > <sg21_at_[hidden]> wrote:
> >> A short question:
> >>
> >> is it true that it is not specified how often and in which order contracts (pre post conditions) are evaluated,
> >> and if it is, I wonder what is means for 'as close as possible'
> > See [basic.contract.eval]/18, [expr.call]/7, and [expr.call]/9.
> _______________________________________________
> SG15 mailing list
> SG15_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/sg15

Received on 2025-10-17 10:26:25