p3465 referenced by the Sean's proposal is pursuing p1179 as a lifetime safety profile. I've briefly looked at the p1179 and I will try to explain how i understand this proposal accomplished the safety in this situation. Note that p1179 uses annotations, but it attempts to minimize the required manual annotation and maximize compiler generated ones. Containers are annotated as Owners, and views, references and pointers are annotated as `Pointer`s. All non-const `Owner` methods by default invalidate the owned object, so any `Pointer` that points to the same object is also invalidated. That means that by default a method like std::vector<T>::insert(const T&) cannot accept a reference that shares a lifetime with the vector itself. So if func() from example calls any method that potentially invalidates vec, thanfunc()will be annotated such that vec and x cannot share a lifetime.
So you're saying any function that has a container parameter (map, list, vector, etc) and any other reference or pointer parameter that could alias into that container, which calls a method on the container won't compile under the Safety profile unless an annotation is added to it?
View all comments
Show parent comment
8
u/Dooez Oct 25 '24 edited Oct 25 '24
p3465 referenced by the Sean's proposal is pursuing p1179 as a lifetime safety profile.
I've briefly looked at the p1179 and I will try to explain how i understand this proposal accomplished the safety in this situation.
Note that p1179 uses annotations, but it attempts to minimize the required manual annotation and maximize compiler generated ones.
Containers are annotated as
Owners, and views, references and pointers are annotated as `Pointer`s. All non-const `Owner` methods by default invalidate the owned object, so any `Pointer` that points to the same object is also invalidated.That means that by default a method like
std::vector<T>::insert(const T&)cannot accept a reference that shares a lifetime with the vector itself. So iffunc()from example calls any method that potentially invalidatesvec, thanfunc()will be annotated such thatvecandxcannot share a lifetime.