-
Notifications
You must be signed in to change notification settings - Fork 13
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
Initialisation behaves differently in an unsafe function #51
Comments
The [safety] features enables the new ownership object relocation. Your old code breaks under [safety] because the old code uses the legacy object model, which is a lot different. If you want to harden existing code with the [safety] feature you'll have to adapt it to the new object model. The new object model is significantly different because, due to relocation, an object's lexical scope does not indicate when it's initialized. If you Long answer short: use explicit initialization. |
Thank you for the explanation. One thing that's still not clear to me is why wouldn't the legacy declaration This new object model is now also having me wondering what happens when a class is defined over multiple different files. For example, what if the class definition is in a file with safety on, and the member function definitions are in a file where safety isn't on. And what about the opposite case, and hybrid cases. I'll toy around with these ideas using compiler explorer to figure that out. |
My view on initialization is that it should be explicit. There would be a lot of intelligence going into determining if something is default initialized or not, and the user can't know at definition (again, thanks to specialization). Simply requiring explicit initialization is the only rule with a clear meaning. As far as |
The following program is currently ill-formed. I believe it shouldn't be. In order to make incremental adoption easy, adding
#feature on safety
at the top of a preexisting valid c++ program shouldn't make it ill-formed. This way, I can enable safety in a 20k lines cpp files and gradually start creatingsafe
functions and types without changing everything all at once.Here are some excerpts from the current draft that contradict my intuition that adding
#feature on safety
on an existing valid C++ program should keep compiling the same:In order to solve this contradiction, I would expect the above to hold by adding
safe
to thefunc
function.The text was updated successfully, but these errors were encountered: