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 15762 - Array casts involving const enums can be made @safe #5878

Merged
merged 1 commit into from Jun 26, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/dcast.d
Expand Up @@ -2730,6 +2730,15 @@ extern (C++) bool typeMerge(Scope* sc, TOK op, Type* pt, Expression* pe1, Expres
}
assert(t2);

if (t1.mod != t2.mod &&
t1.ty == Tenum && t2.ty == Tenum &&
(cast(TypeEnum)t1).sym == (cast(TypeEnum)t2).sym)
{
ubyte mod = MODmerge(t1.mod, t2.mod);
t1 = t1.castMod(mod);
t2 = t2.castMod(mod);
}

Lagain:
t1b = t1.toBasetype();
t2b = t2.toBasetype();
Expand Down
6 changes: 6 additions & 0 deletions src/denum.d
Expand Up @@ -628,7 +628,10 @@ extern (C++) final class EnumMember : VarDeclaration
origValue = e;

if (!ed.isAnonymous())
{
e = e.castTo(sc, ed.type);
e = e.ctfeInterpret();
}
}
else if (origType)
{
Expand Down Expand Up @@ -660,7 +663,10 @@ extern (C++) final class EnumMember : VarDeclaration
origValue = e;

if (!ed.isAnonymous())
{
e = e.castTo(sc, ed.type);
e = e.ctfeInterpret();
}
value = e;
}
else
Expand Down
3 changes: 2 additions & 1 deletion src/mtype.d
Expand Up @@ -8848,7 +8848,8 @@ extern (C++) final class TypeEnum : Type
{
if (!sym.members && !sym.memtype)
return this;
return sym.getMemtype(Loc()).toBasetype();
auto tb = sym.getMemtype(Loc()).toBasetype();
return tb.castMod(mod); // retain modifier bits from 'this'
}

override Expression defaultInit(Loc loc)
Expand Down
13 changes: 13 additions & 0 deletions test/compilable/test15762.d
@@ -0,0 +1,13 @@
// https://issues.dlang.org/show_bug.cgi?id=15762

enum Windows1252Char : ubyte { init }

void main() @safe {
ubyte[] a = [1, 2, 3, 4];
auto aw = cast(Windows1252Char[]) a;
auto caw = cast(const(Windows1252Char)[]) a;
const(ubyte)[] c = [1, 2, 3, 4];
auto d = cast(const(ubyte)[]) c;
auto e = cast(const(Windows1252Char)[]) c;
}