diff --git a/src/ctfeexpr.c b/src/ctfeexpr.c index 8df1390c6590..3ed479e4a2bb 100644 --- a/src/ctfeexpr.c +++ b/src/ctfeexpr.c @@ -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(); } diff --git a/test/fail_compilation/ctfe14207.d b/test/fail_compilation/ctfe14207.d new file mode 100644 index 000000000000..511f7553c2d6 --- /dev/null +++ b/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();