-
-
Notifications
You must be signed in to change notification settings - Fork 424
add staticError helper to throw @nogc Errors #1325
Conversation
Hopefully throwing Error while an Error is in flight shouldn't happen. |
// pure hack, what we actually need is @noreturn and allow to call that in pure functions | ||
static T get() | ||
{ | ||
_store[0 .. __traits(classInstanceSize, T)] = typeid(T).init[]; |
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.
Should probably add:
static assert(__traits(classInstanceSize, T) <= _store.length),
T.stringof ~ " is too large for staticError()");
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.
It would already fail to compile, but with a worse error message.
@MartinNowak - address comment by @schuetzm and it should be good to go |
Done |
Auto-merge toggled on |
add staticError helper to throw @nogc Errors
T.stringof ~ " is too large for staticError()"); | ||
|
||
_store[0 .. __traits(classInstanceSize, T)] = typeid(T).init[]; | ||
return cast(T) _store.ptr; |
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.
Is this safe regarding alignment of the T
/Error
type?
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.
ping @MartinNowak
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.
You might be right, will check.
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.
It doesn't seem to be a problem, the array is 16-byte aligned and we don't align classes (see).
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.
Why would 16 byte alignment be guaranteed for the array?
This pull request introduced a regression: |
No description provided.