Date: Fri, 17 Oct 2025 16:27:55 +0200
Am 17.10.2025 um 15:53 schrieb Harald Achitz via SG15:
>
> Today's
>
> void fun(Foo* ptr) {
> my_supper_assert_macro (ptr!=nullpter);
> my_supper_assert_macro(ptr->hasData());
> }
>
> should not have any problems, ever
>
This isn't true - at least not in general. It totally depends what
'my_supper_assert_macro()' expands into, and what the expanded code
does. If it doesn't terminate before 'ptr' is dereferenced, your program
will face UB just like it always did. On top of that, the expanded code
may be different in every TU. This is obviously IF-NDR but also the sad
reality.
>
>
> so replacing this blindly against
>
> void fun(Foo* ptr) {
> contract_assert (ptr!=nullpter);
> contract_assert(ptr->hasData());
> }
>
> does not work, as I understand, since observe could be a problem?
>
> (I know now that when using pre I have to re-write with &&)
>
The same reasoning applies to all contract assertions, not only 'pre()'.
~Dani
> /Harald
>
>
>
>
> _______________________________________________
> SG15 mailing list
> SG15_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/sg15
>
> Today's
>
> void fun(Foo* ptr) {
> my_supper_assert_macro (ptr!=nullpter);
> my_supper_assert_macro(ptr->hasData());
> }
>
> should not have any problems, ever
>
This isn't true - at least not in general. It totally depends what
'my_supper_assert_macro()' expands into, and what the expanded code
does. If it doesn't terminate before 'ptr' is dereferenced, your program
will face UB just like it always did. On top of that, the expanded code
may be different in every TU. This is obviously IF-NDR but also the sad
reality.
>
>
> so replacing this blindly against
>
> void fun(Foo* ptr) {
> contract_assert (ptr!=nullpter);
> contract_assert(ptr->hasData());
> }
>
> does not work, as I understand, since observe could be a problem?
>
> (I know now that when using pre I have to re-write with &&)
>
The same reasoning applies to all contract assertions, not only 'pre()'.
~Dani
> /Harald
>
>
>
>
> _______________________________________________
> SG15 mailing list
> SG15_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/sg15
-- PGP/GPG: 2CCB 3ECB 0954 5CD3 B0DB 6AA0 BA03 56A1 2C4638C5
Received on 2025-10-17 14:28:06
