Skip to content

Commit

Permalink
Extend lowering tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kinke committed Apr 7, 2020
1 parent e1903d3 commit 818447c
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions test/runnable/testassert.d
Expand Up @@ -75,6 +75,8 @@ void test20114()
assert(c == "1 != 0");
}

version (DigitalMars) version (Win64) version = DMD_Win64;

extern(C) int printf(const(char)* fmt, ...) @safe; // non-nothrow hack

void test20375() @safe
Expand All @@ -89,6 +91,7 @@ void test20375() @safe
}

static int instances;
static int postblits;

this(bool) @safe
{
Expand All @@ -98,11 +101,12 @@ void test20375() @safe
this(this) @safe
{
instances++;
postblits++;
}

~this() @safe
{
printf("dtor\n"); // non-nothrow hack
printf("dtor\n"); // make the dtor non-nothrow
assert(instances > 0);
instances--;
}
Expand All @@ -115,18 +119,53 @@ void test20375() @safe

{
auto a = RefCounted.create();
assert(a == RefCounted.create());
assert(a == RefCounted()); // both operands are pure expressions => no temporaries
}

assert(RefCounted.instances == 0);
assert(RefCounted.postblits == 0);

{
auto a = RefCounted.create();
const msg = getMessage(assert(a != RefCounted.create()));
assert(a == RefCounted.create()); // impure rhs is promoted to a temporary lvalue => copy for a.opEquals(rhs)
}

assert(RefCounted.instances == 0);
assert(RefCounted.postblits == 1);
RefCounted.postblits = 0;

{
const msg = getMessage(assert(RefCounted.create() != RefCounted.create())); // both operands promoted to temporary lvalues
assert(msg == "RefCounted() == RefCounted()");
}

version (none) //(DMD_Win64) // FIXME: temporaries apparently not destructed when unwinding via AssertError
{
assert(RefCounted.instances >= 0 && RefCounted.instances <= 2);
RefCounted.instances = 0;
}
else
assert(RefCounted.instances == 0);
assert(RefCounted.postblits == 1);
RefCounted.postblits = 0;

static int numGetLvalImpureCalls = 0;
ref RefCounted getLvalImpure() @trusted
{
numGetLvalImpureCalls++;
__gshared lval = RefCounted(); // not incrementing RefCounted.instances
return lval;
}

{
const msg = getMessage(assert(getLvalImpure() != getLvalImpure())); // both operands promoted to ref temporaries
assert(msg == "RefCounted() == RefCounted()");
}

assert(numGetLvalImpureCalls == 2);
assert(RefCounted.instances == 0);
assert(RefCounted.postblits == 1);
RefCounted.postblits = 0;
}

string getMessage(T)(lazy T expr) @trusted
Expand Down

0 comments on commit 818447c

Please sign in to comment.