dmd/compiler/test/runnable/testaliascast.d
Dennis 307be0b328
Merge stable (#15429)
* druntime: Restrict some `pragma(inline, false)` kludges to DMD only

They appear related to DMD's inlining at the AST level; LDC at least
doesn't need them, so let the optimizer decide for non-DMD backends.

* Fix little C++ header regression

* Expose VarArg.KRvariadic to C++ headers

* Revert "Deprecate alias this for classes v2 (#14812)" (#15326)

This reverts commit af7817b4ae.

* Add changelog for catch qualifier deprecation & update release no

---------

Co-authored-by: Martin Kinkelin <noone@nowhere.com>
Co-authored-by: Walter Bright <WalterBright@users.noreply.github.com>
Co-authored-by: Nick Treleaven <ntrel002@gmail.com>
2023-07-18 10:55:05 +02:00

63 lines
856 B
D

// 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();
}