-
-
Notifications
You must be signed in to change notification settings - Fork 743
Fix 14477, Nullable on struct with @disable this() #3213
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
Conversation
✅ |
Doesn't this make Nullable intrinsically unusable in safe code? |
LGTM. |
My brain says yes, but DMD says no. I've marked the unittest as safe and it compiles and runs without error or warning. |
It's un- |
@schuetzm Either I'm misunderstanding you or DMD isn't properly enforcing @safe. My latest commit adds indirections to the unittest and it still happily compiles. |
@jwhear It's indeed a bug. Reported here: https://issues.dlang.org/show_bug.cgi?id=14496 |
@schuetzm Thanks for filing. I'm wondering if T foo; // won't compile
T baz = void; // unsafe in user code
Nullable!T bar; // the user can do this to be @safe The rationale being that |
Currently it cannot be |
ba96630
to
0e81b61
Compare
Squashed to a single commit. Substantial changes, please re-review.
|
|
Is there a problem with using
|
Right, that's a good idea! It still leaves the possibility that |
The "mostest correct" alternative would be (IMO) to emplace on first assignment, and destroy when nullifying (which is what I'd expect ffrom null-ifying, BTW). But this is already good enough. As for ~this, I'm 99% sure spec mandates it never chokes on LGTM (once changed to T.init) |
Now uses |
private T _value; | ||
/* T may be a struct with a @disabled this: | ||
-If T supports default-initialization do so to allow use with @safe code | ||
-If T does not support it then initialize with void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of date comment. Mostly irrelevent now (see next comment).
Initializes `_value` explicitly with `.init` to allow wrapping of structs with a disabled default constructor. Adds unittests Fix 14477
@monarchdodra @schuetzm Updated and dramatically simplified with |
I'm not really happy with this change. When a struct is marked as Currently, doing it this way is a blatant violation of default initializing something that has a disabled this. The compiler refused to compile the code, and I think it was correct in doing so. A workaround is to always initialize your nullable to a value, and make null afterwards. If we really want this to work, that I'd really favor we go for an emplace/destroy scheme on every call to first-initialization/nullify. That would be guaranteed correct. |
@monarchdodra Sounds like you have a better handle on this than I do. Would you be willing to make a PR of your own to address this? If so, I'd be happy to close this one. |
I am totally overbooked, and don't even have a working environment from which to push from. Besides, I'm sure you can manage. If people who had a better handle always stepped in, we'd get nowhere fast. |
I'm closing this; when I'm able to put together another stab at it, I'll open another PR. |
https://issues.dlang.org/show_bug.cgi?id=14477
Simple change to initialize Nullable's internal value to void, allowing structs with disabled default constructors to be stored. This is desirable because Nullable is the obvious tool for wrapping such structs such that they can be default initialized.
Adds unittest.
Fix 14477