-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] implement a borrow checker? #252
Comments
This explains it better: https://rustc-dev-guide.rust-lang.org/borrow_check.html |
I don't think it is feasible to implement a borrow checker at transpiler level, correct me if i'm wrong. |
Rust-style borrow checker is good for static analysis and whatnot, but it requires the language to be structured around it, which would require C++2 to have a native compiler and would most likely break interoperability with "classic" C++ code, or at least would require API shims. That being said, having builtin facilities to enable static analysis (beyond local lifetime analysis) is a good idea. |
From the page you mentioned:
main: () -> int = {
i : int;
fun(i);
}
fun: (i : int) = {
std::cout << i << std::endl;
} ends with an error:
Some points will be covered by |
Also to add, point 2 (and to extent, 3-5) does not apply to C++, since C++ move works differently from Rust's, as such move does not invalidate an object, so you can move as many times as you want. |
The borrowing topic probably is related to an issue that was already identified in cppfront:
More here: #231 (comment) |
Would it be possible for a Rust-like move to be added in a C++ transpiler as sugar around |
Having only one Mutable borrow in rust is what I think is too restrictive. For multi-threaded programs, we can fall back to rust-like restrictions. Val's model of safety is similar to rust's which I think is equally restrictive but it is worth looking into val's projections and subscripts. |
@filipsajdak covered it... this is intended to be covered primarily by the above-linked Lifetime static analysis which is not yet implemented in cppfront (and secondarily by things like guaranteed initialization, that one is already implemented in cppfront). |
In rust they implement a borrow checker to stop some undefined and stop buffer overflows would it be adventurous to have one in cpp2?
The text was updated successfully, but these errors were encountered: