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

fix Issue 14596 - Error: e2ir: cannot cast malloc(42u) of type void* … #4667

Merged
merged 1 commit into from
May 19, 2015

Conversation

Kozzi11
Copy link
Contributor

@Kozzi11 Kozzi11 commented May 18, 2015

…to type char[]

@yebblies
Copy link
Member

Does a similar issue exist for static arrays?

@Kozzi11
Copy link
Contributor Author

Kozzi11 commented May 18, 2015

Yep, it exist, I will add this fix too

void main() {
import core.stdc.stdlib : malloc;
auto ptr = cast(char[]) malloc(42);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

As a better place, you can add the new test case to fail_compilation/fail_casting.d.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can also remove the dependency to druntime as follows.

void* p = null;
auto arr = cast(char[])p;

And using malloc function is not good for a platform independent test case. It takes size_t parameter, so the integer value 42 will be uint in 32bit target, and ulong in 64bit target. Finally the difference will appear in the error message.

Let's not use it to fix the current auto-tester failure.

@Kozzi11 Kozzi11 force-pushed the 14596 branch 2 times, most recently from 646ee84 to 2bcf5dc Compare May 18, 2015 18:34
@WalterBright
Copy link
Member

Auto-merge toggled on

WalterBright added a commit that referenced this pull request May 19, 2015
fix Issue 14596 - Error: e2ir: cannot cast malloc(42u) of type void* …
@WalterBright WalterBright merged commit d872b5a into dlang:master May 19, 2015
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

Successfully merging this pull request may close these issues.

4 participants