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 13392 and 11294 - class + alias this + cast(void*) == overzealous cast #9017

Merged
merged 1 commit into from
Nov 29, 2018
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
4 changes: 2 additions & 2 deletions src/dmd/opover.d
Original file line number Diff line number Diff line change
Expand Up @@ -828,10 +828,10 @@ Expression op_overload(Expression e, Scope* sc)
/* Rewrite op(e1) as:
* op(e1.aliasthis)
*/
Expression e1 = new DotIdExp(e.loc, e.e1, ad.aliasthis.ident);
Expression e1 = resolveAliasThis(sc, e.e1);
result = e.copy();
(cast(UnaExp)result).e1 = e1;
result = result.trySemantic(sc);
result = result.op_overload(sc);
return;
}
}
Expand Down
63 changes: 63 additions & 0 deletions test/runnable/testaliascast.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// https://issues.dlang.org/show_bug.cgi?id=11294

string result;

extern(C) void rt_finalize(void *ptr, bool det=true);
void clear(T)(T obj) if (is(T == class))
{
rt_finalize(cast(void*)obj);
}

class A
{
~this() { result ~= "A"; }
string dummy = "0";
}

class B
{
A a;
string dummy = "0";
alias a this;
~this() { result ~= "B"; }
}

void test11294()
{
auto a = new A;
auto b = new B;
b.a = a;
result ~= b.dummy;
clear(b);
result ~= a.dummy;
result ~= "END";
clear(a);

assert(result == "0B0ENDA");
}


// https://issues.dlang.org/show_bug.cgi?id=13392
void foo(T)(T t)
{
void* p = cast(void*) t; //Callas alias this
}

class X {}

class Y
{
alias a this;
@property X a(){assert(0);} //Here
}

void test13392()
{
foo(B.init);
}

void main()
{
test11294();
test13392();
}