Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Fix Issue 20346 - std.uuid does not compile with checkaction=context
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonlightSentinel committed Nov 2, 2019
1 parent cfef0ae commit 6cca8a0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/core/internal/dassert.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on assertion failures
module core.internal.dassert;

/// Allows customized assert error messages
string _d_assert_fail(string comp, A, B)(auto ref A a, auto ref B b)
string _d_assert_fail(string comp, A, B)(auto ref const A a, auto ref const B b)
{
/*
The program will be terminated after the assertion error message has
Expand Down Expand Up @@ -64,7 +64,7 @@ private template getPrintfFormat(T)
Minimalistic formatting for use in _d_assert_fail to keep the compilation
overhead small and avoid the use of Phobos.
*/
private string miniFormat(V)(ref V v)
private string miniFormat(V)(const ref V v)
{
import core.stdc.stdio : sprintf;
import core.stdc.string : strlen;
Expand All @@ -90,10 +90,15 @@ private string miniFormat(V)(ref V v)
{
return "`null`";
}
else static if (__traits(compiles, { string s = V.init.toString(); }))
else static if (__traits(compiles, { string s = v.toString(); }))
{
return v.toString();
}
// Non-const toString(), e.g. classes inheriting from Object
else static if (__traits(compiles, { string s = V.init.toString(); }))
{
return (cast() v).toString();
}
else static if (is(V : U[], U))
{
import core.internal.traits: Unqual;
Expand Down Expand Up @@ -215,7 +220,7 @@ private auto assumeFakeAttributes(T)(T t) @trusted
return cast(type) t;
}

private string miniFormatFakeAttributes(T)(ref T t)
private string miniFormatFakeAttributes(T)(const ref T t)
{
alias miniT = miniFormat!T;
return assumeFakeAttributes(&miniT)(t);
Expand Down
31 changes: 31 additions & 0 deletions test/exceptions/src/assert_fail.d
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ void testToString()()
}
}
test(new Foo("a"), new Foo("b"), "Foo(a) != Foo(b)");

// Verifiy that the const toString is selected if present
static struct Overloaded
{
string toString()
{
return "Mutable";
}

string toString() const
{
return "Const";
}
}

test!"!="(Overloaded(), Overloaded(), "Const is Const");
}


Expand Down Expand Up @@ -163,6 +179,20 @@ void testTemporary()
assert(Bad() == Bad());
}

void testEnum()
{
static struct UUID {
union
{
ubyte[] data = [1];
}
}

ubyte[] data;
enum ctfe = UUID();
test(assert(ctfe.data == data), "[1] != []");
}

void main()
{
testIntegers();
Expand All @@ -176,5 +206,6 @@ void main()
testAttributes();
testVoidArray();
testTemporary();
testEnum();
fprintf(stderr, "success.\n");
}

0 comments on commit 6cca8a0

Please sign in to comment.