Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

add staticError helper to throw @nogc Errors #1325

Merged
merged 1 commit into from
Jul 26, 2015

Conversation

MartinNowak
Copy link
Member

No description provided.

@DmitryOlshansky
Copy link
Member

Hopefully throwing Error while an Error is in flight shouldn't happen.
After all Error is not recoverable so LGTM

// 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[];

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()");

Copy link
Member Author

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.

@DmitryOlshansky
Copy link
Member

@MartinNowak - address comment by @schuetzm and it should be good to go

@MartinNowak
Copy link
Member Author

Done

@DmitryOlshansky
Copy link
Member

Auto-merge toggled on

DmitryOlshansky added a commit that referenced this pull request Jul 26, 2015
add staticError helper to throw @nogc Errors
@DmitryOlshansky DmitryOlshansky merged commit bce3f9b into dlang:master Jul 26, 2015
T.stringof ~ " is too large for staticError()");

_store[0 .. __traits(classInstanceSize, T)] = typeid(T).init[];
return cast(T) _store.ptr;
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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.

Copy link
Member Author

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).

Copy link
Member

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?

@MartinNowak MartinNowak deleted the nogcError branch July 28, 2015 10:20
@CyberShadow
Copy link
Member

This pull request introduced a regression:
https://issues.dlang.org/show_bug.cgi?id=14993

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

Successfully merging this pull request may close these issues.

6 participants