r/cpp • • Mar 27 '26

C++26: A User-Friendly assert() macro

https://www.sandordargo.com/blog/2026/03/25/cpp26-user-friendly-assert
53 Upvotes

27 comments sorted by

View all comments

Show parent comment

10

u/James20k P2005R0 Mar 27 '26 edited Mar 27 '26

This is one of the reasons why I dislike the current state of contracts: if you do this you will run into unexpected undefined behaviour. Contracts do not make the same guarantees as asserts by design, and doing this is a great way to introduce security vulnerabilities into your code

Contract conversion has to be carefully evaluated - you absolutely cannot swap assert for contract_assert