Skip to content
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

new in safe contexts #42

Open
cmazakas opened this issue Sep 10, 2024 · 1 comment
Open

new in safe contexts #42

cmazakas opened this issue Sep 10, 2024 · 1 comment

Comments

@cmazakas
Copy link
Collaborator

Assume a simple function like:

box<T> box<T>::make() safe {
  unsafe { return box(new T()); }
}

It's easy to introduce a soundness hole here.

The intent is that this function is sound because even if allocation is unsafe and fails, we simply OOM so we panic and stop execution. We intend that in a safe context only a safe default constructor will be called but new being unsafe necessitates a block where it's easy to silently mask that we now also permit unsafe default constructors, which permits a soundness hole.

Also see: https://godbolt.org/z/xM556saPr

@seanbaxter
Copy link
Collaborator

seanbaxter commented Sep 10, 2024

May ultimately want safe new and safe delete operator names.
For safe delete, the operator should be safe and take a special type for the pointer that has an unsafe constructor. That moves the unsafe proof to the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants