profiles cannot know whether this is safe to use. Inside the body, compiler doesn't know whether the arguments alias. At call site, compiler doesn't know whether this function accepts aliased inputs or not.
With safe-cpp, this is valid code. Because it uses the same aliasing model as rust (only one exclusive mutable borrow active at a time).
#feature on safety
#include <https://raw.githubusercontent.com/cppalliance/safe-cpp/master/libsafecxx/single-header/std2.h?token=$(date%20+%s)>
extern void func(std2::vector<int>^ vec, int^ x);
int main() {
std2::vector<int> vec {};
//int^ x = mut vec[0];
func(^vec, mut vec[0]);
return 0;
}
error message:
safety: during safety checking of int main()
borrow checking: example.cpp:11:20
func(^vec, mut vec[0]);
^
mutable borrow of vec between its mutable borrow and its use
loan created at example.cpp:11:10
func(^vec, mut vec[0]);
^
View all comments
Show parent comment
2
u/kronicum Oct 25 '24
Look again at the assertion of the parent comment.
Which is fine, but useless for the assertion in question.