@@ -83,7 +83,7 @@ int __cmp(T)(scope const T[] lhs, scope const T[] rhs) @trusted
83
83
// This function is called by the compiler when dealing with array
84
84
// comparisons in the semantic analysis phase of CmpExp. The ordering
85
85
// comparison is lowered to a call to this template.
86
- int __cmp (T1 , T2 )(T1 [] s1, T2 [] s2)
86
+ auto __cmp (T1 , T2 )(T1 [] s1, T2 [] s2)
87
87
if (! __traits(isScalar, T1 ) && ! __traits(isScalar, T2 ))
88
88
{
89
89
import core.internal.traits : Unqual;
@@ -237,3 +237,26 @@ if (!__traits(isScalar, T1) && !__traits(isScalar, T2))
237
237
auto vb = [cast (void [])b[0 ], b[1 ]];
238
238
assert (less2(va, vb));
239
239
}
240
+
241
+ // custom aggregate types
242
+ @safe unittest
243
+ {
244
+ // https://issues.dlang.org/show_bug.cgi?id=24044
245
+ // Support float opCmp(...) with array
246
+ static struct F
247
+ {
248
+ float f;
249
+ float opCmp (F other) const { return this .f - other.f; }
250
+ }
251
+
252
+ F[2 ] a = [F(1.0f ), F(float .nan)];
253
+ F[2 ] b = [F(1.0f ), F(1.0f )];
254
+ F[1 ] c = [F(1.0f )];
255
+
256
+ bool isNan (float f) { return f != f; }
257
+
258
+ assert (isNan(__cmp(a, b)));
259
+ assert (isNan(__cmp(a, a)));
260
+ assert (__cmp(b, b) == 0 );
261
+ assert (__cmp(a, c) > 0 );
262
+ }
0 commit comments