Skip to content

Commit

Permalink
Merge pull request #4667 from Kozzi11/14596
Browse files Browse the repository at this point in the history
fix Issue 14596 - Error: e2ir: cannot cast malloc(42u) of type void* …
  • Loading branch information
WalterBright committed May 19, 2015
2 parents bd25986 + 2bcf5dc commit d872b5a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cast.c
Expand Up @@ -1510,6 +1510,12 @@ Expression *castTo(Expression *e, Scope *sc, Type *t)
{
goto Lfail;
}
// Bugzilla 14596: Tpointer --> T(s)array
if ((tob->ty == Tarray || tob->ty == Tsarray) && t1b->ty == Tpointer)
{
goto Lfail;
}

// Bugzilla 10646: Tclass <--> (T[] or T[n])
if (tob->ty == Tclass && (t1b->ty == Tarray || t1b->ty == Tsarray) ||
t1b->ty == Tclass && (tob->ty == Tarray || tob->ty == Tsarray))
Expand Down
14 changes: 14 additions & 0 deletions test/fail_compilation/fail_casting.d
Expand Up @@ -178,3 +178,17 @@ void test14093()
Tuple14093!(int, "x", int, "y") point;
auto newPoint = cast(Object)(point);
}

/*
TEST_OUTPUT:
---
fail_compilation/fail_casting.d(192): Error: cannot cast expression p of type void* to char[]
fail_compilation/fail_casting.d(193): Error: cannot cast expression p of type void* to char[2]
---
*/
void test14596()
{
void* p = null;
auto arr = cast(char[])p;
char[2] sarr = cast(char[2])p;
}

0 comments on commit d872b5a

Please sign in to comment.