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

-2

u/germandiago Oct 25 '24

Little time now but basically non-const functions (in a Bjarne paper) would assume that calling a non const func would invalidate pointers (in this model iterators, spans, string_view, etc.) are also pointers.

In order for the type system to know this is not the case it does need an annotation in this case.  [[not_invalidating]] annotation I think he called it. Of course that is not a final proposal but a strategy to del with such things.

Everything else would be assumed unsafe (I mean if not marking things correctly). Conclusion: it does not leak unsafety.

The point here is to understand that this strategy is more potentially more conservative than Safe C++ but also more compatible and there is no reason for it to leak. It is usable? I think that yes. But no full implementation exists yet.

C++ type system cannot solve all. 

This is about subsets that do not leak. There are different such subsets.

4

u/Nickitolas Oct 26 '24

> Conclusion: it does not leak unsafety.

It's not really clear to me from your explanation how this is supposed to work and in which location/s the compiler errors. Could you provide some examples? Ideally 4, for the full matrix of "func allows/does not allow aliasing" and "the caller passes in an aliasing/non-aliasing pair of parameters"