Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
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
21 changes: 20 additions & 1 deletion src/core/internal/dassert.d
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,21 @@ private string miniFormat(V)(const ref V v)
import core.internal.traits: isAggregateType;
import core.stdc.stdio : sprintf;
import core.stdc.string : strlen;
static if (is(V : bool))

static if (is(V == shared T, T))
{
// Use atomics to avoid race conditions whenever possible
static if (__traits(compiles, atomicLoad(v)))
{
T tmp = cast(T) atomicLoad(v);
return miniFormat(tmp);
}
else
{ // Fall back to a simple cast - we're violating the type system anyways
return miniFormat(*cast(T*) &v);
}
}
else static if (is(V == bool))
{
return v ? "true" : "false";
}
Expand Down Expand Up @@ -189,6 +203,11 @@ private string miniFormat(V)(const ref V v)
}
}

// This should be a local import in miniFormat but fails with a cyclic dependency error
// core.thread.osthread -> core.time -> object -> core.internal.array.capacity
// -> core.atomic -> core.thread -> core.thread.osthread
import core.atomic : atomicLoad;

// Inverts a comparison token for use in _d_assert_fail
private string invertCompToken(string comp)
{
Expand Down
7 changes: 7 additions & 0 deletions test/exceptions/src/assert_fail.d
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void testIntegers()()
test(uint.min, uint.max, "0 != 4294967295");
test(long.min, long.max, "-9223372036854775808 != 9223372036854775807");
test(ulong.min, ulong.max, "0 != 18446744073709551615");
test(shared(ulong).min, shared(ulong).max, "0 != 18446744073709551615");

int testFun() { return 1; }
test(testFun(), 2, "1 != 2");
Expand Down Expand Up @@ -79,6 +80,9 @@ void testToString()()
}
test(new Foo("a"), new Foo("b"), "Foo(a) != Foo(b)");

scope f = cast(shared) new Foo("a");
test!"!="(f, f, "Foo(a) == Foo(a)");

// Verifiy that the const toString is selected if present
static struct Overloaded
{
Expand Down Expand Up @@ -135,6 +139,9 @@ void testStruct()()

NoCopy n;
test(_d_assert_fail!"!="(n, n), "NoCopy() == NoCopy()");

shared NoCopy sn;
test(_d_assert_fail!"!="(sn, sn), "NoCopy() == NoCopy()");
}

void testAA()()
Expand Down