Skip to content

Commit

Permalink
Merge pull request dlang#4545 from 9rnsr/fix14207
Browse files Browse the repository at this point in the history
[REG2.065] Issue 14207 - [CTFE] ICE on unsupported reinterpret cast in compile time
Conflicts:
	src/interpret.c

Signed-off-by: Martin Krejcirik <mk@krej.cz>
  • Loading branch information
WalterBright authored and tramker committed May 20, 2015
1 parent c786c8a commit 176ea43
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/ctfeexpr.c
Expand Up @@ -569,8 +569,15 @@ bool isSafePointerCast(Type *srcPointee, Type *destPointee)
// It's OK if they are the same size (static array of) integers, eg:
// int* --> uint*
// int[5][] --> uint[5][]
return srcPointee->baseElemOf()->isintegral() &&
destPointee->baseElemOf()->isintegral() &&
if (srcPointee->ty == Tsarray && destPointee->ty == Tsarray)
{
if (srcPointee->size() != destPointee->size())
return false;
srcPointee = srcPointee->baseElemOf();
destPointee = destPointee->baseElemOf();
}
return srcPointee->isintegral() &&
destPointee->isintegral() &&
srcPointee->size() == destPointee->size();
}

Expand Down
22 changes: 22 additions & 0 deletions test/fail_compilation/ctfe14207.d
@@ -0,0 +1,22 @@
/*
TEST_OUTPUT:
---
fail_compilation/ctfe14207.d(13): Error: cannot convert &immutable(ulong) to ubyte[8]* at compile time
fail_compilation/ctfe14207.d(18): called from here: nativeToBigEndian()
fail_compilation/ctfe14207.d(22): called from here: digest()
---
*/

ubyte[8] nativeToBigEndian()
{
immutable ulong res = 1;
return *cast(ubyte[8]*) &res;
}

auto digest()
{
ubyte[8] bits = nativeToBigEndian();
return bits;
}

enum h = digest();

0 comments on commit 176ea43

Please sign in to comment.