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

[REG2.064a] Issue 10687 - Refused cast from uint[] to array of uint-based enums at compile-time #2612

Merged
merged 1 commit into from
Oct 3, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/ctfeexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,12 @@ bool isSafePointerCast(Type *srcPointee, Type *destPointee)
if (destPointee->ty == Tvoid)
return true;

// It's OK if they are the same size integers, eg int* and uint*
return srcPointee->isintegral() && destPointee->isintegral()
&& srcPointee->size() == destPointee->size();
// 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() &&
srcPointee->size() == destPointee->size();
}

Expression *getAggregateFromPointer(Expression *e, dinteger_t *ofs)
Expand Down
6 changes: 5 additions & 1 deletion test/runnable/interpret.d
Original file line number Diff line number Diff line change
Expand Up @@ -3113,12 +3113,16 @@ void test112()
// 10687

enum Foo10687 : uint { A, B, C, D, E }
immutable uint[5][] m10687 = [[0, 1, 2, 3, 4]];

void test10687()
{
static immutable uint[5] a1 = [0, 1, 2, 3, 4];
auto a2 = cast(immutable(Foo10687[5]))a1;
auto a2 = cast(immutable(Foo10687[5]))a1;
static a3 = cast(immutable(Foo10687[5]))a1;

auto foos1 = cast(immutable(Foo10687[5][]))m10687;
static foos2 = cast(immutable(Foo10687[5][]))m10687;
}

/************************************************/
Expand Down