r/cpp • • Oct 24 '24 • Take My Silver 1

Why Safety Profiles Failed

https://www.circle-lang.org/draft-profiles.html
180 Upvotes

347 comments sorted by

View all comments

Show parent comment

12

u/seanbaxter Oct 26 '24

It's always possible to use a safe class unsafely from an unsafe context. Same as in Rust. If you dereference a dangling pointer, borrow from that lvalue, and pass it to a safe function, that's an unsound use. The guarantee is that UB won't originate from safe code, not that safe code is impossible to use in an unsound manner.

12

u/matthieum Oct 26 '24

Okay, so in that case Safe C++ is actually not viral at all, and can be mixed in an older codebase easily then. That's great.

3

u/TheoreticalDumbass :illuminati: Oct 26 '24

if i pass aliasing references to safe code expecting them to not alias, is the UB at the callsite of safe code?

5

u/seanbaxter Oct 26 '24

Basically yes. Safe functions have defined behavior for all valid inputs. Mutable references that alias are not valid inputs. In a safe context, the compiler upholds that invariant. In an unsafe context it's up to the user not to break it with unsafe operations.