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@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/sg15


--
PGP/GPG: 2CCB 3ECB 0954 5CD3 B0DB 6AA0 BA03 56A1 2C4638C5