This repository was archived by the owner on Oct 12, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,21 @@ private string miniFormat(V)(const ref V v)
75
75
import core.internal.traits : isAggregateType;
76
76
import core.stdc.stdio : sprintf;
77
77
import core.stdc.string : strlen;
78
- static if (is (V : bool ))
78
+
79
+ static if (is (V == shared T, T))
80
+ {
81
+ // Use atomics to avoid race conditions whenever possible
82
+ static if (__traits(compiles, atomicLoad(v)))
83
+ {
84
+ T tmp = cast (T) atomicLoad(v);
85
+ return miniFormat (tmp);
86
+ }
87
+ else
88
+ { // Fall back to a simple cast - we're violating the type system anyways
89
+ return miniFormat (* cast (T* ) &v);
90
+ }
91
+ }
92
+ else static if (is (V == bool ))
79
93
{
80
94
return v ? " true" : " false" ;
81
95
}
@@ -189,6 +203,11 @@ private string miniFormat(V)(const ref V v)
189
203
}
190
204
}
191
205
206
+ // This should be a local import in miniFormat but fails with a cyclic dependency error
207
+ // core.thread.osthread -> core.time -> object -> core.internal.array.capacity
208
+ // -> core.atomic -> core.thread -> core.thread.osthread
209
+ import core.atomic : atomicLoad;
210
+
192
211
// Inverts a comparison token for use in _d_assert_fail
193
212
private string invertCompToken (string comp)
194
213
{
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ void testIntegers()()
29
29
test(uint .min, uint .max, " 0 != 4294967295" );
30
30
test(long .min, long .max, " -9223372036854775808 != 9223372036854775807" );
31
31
test(ulong .min, ulong .max, " 0 != 18446744073709551615" );
32
+ test(shared (ulong ).min, shared (ulong ).max, " 0 != 18446744073709551615" );
32
33
33
34
int testFun () { return 1 ; }
34
35
test(testFun(), 2 , " 1 != 2" );
@@ -79,6 +80,9 @@ void testToString()()
79
80
}
80
81
test(new Foo (" a" ), new Foo (" b" ), " Foo(a) != Foo(b)" );
81
82
83
+ scope f = cast (shared ) new Foo (" a" );
84
+ test! " !=" (f, f, " Foo(a) == Foo(a)" );
85
+
82
86
// Verifiy that the const toString is selected if present
83
87
static struct Overloaded
84
88
{
@@ -135,6 +139,9 @@ void testStruct()()
135
139
136
140
NoCopy n;
137
141
test(_d_assert_fail! " !=" (n, n), " NoCopy() == NoCopy()" );
142
+
143
+ shared NoCopy sn;
144
+ test(_d_assert_fail! " !=" (sn, sn), " NoCopy() == NoCopy()" );
138
145
}
139
146
140
147
void testAA ()()
You can’t perform that action at this time.
0 commit comments