diff --git a/src/object.d b/src/object.d index e360ae4515..3630e9e056 100644 --- a/src/object.d +++ b/src/object.d @@ -4653,17 +4653,33 @@ public import core.internal.switch_: __switch_error; public @trusted @nogc nothrow pure extern (C) void _d_delThrowable(scope Throwable); // Compare class and interface objects for ordering. -private int __cmp(Obj)(Obj lhs, Obj rhs) -if (is(Obj : Object)) +int __cmp(C1, C2)(C1 lhs, C2 rhs) +if ((is(C1 : const(Object)) || (is(C1 == interface) && (__traits(getLinkage, C1) == "D"))) && + (is(C2 : const(Object)) || (is(C2 == interface) && (__traits(getLinkage, C2) == "D")))) { - if (lhs is rhs) + static if (is(C1 == typeof(null)) && is(C2 == typeof(null))) + { return 0; - // Regard null references as always being "less than" - if (!lhs) + } + else static if (is(C1 == typeof(null))) + { + // Regard null references as always being "less than" return -1; - if (!rhs) + } + else static if (is(C2 == typeof(null))) + { return 1; - return lhs.opCmp(rhs); + } + else + { + if (lhs is rhs) + return 0; + if (lhs is null) + return -1; + if (rhs is null) + return 1; + return lhs.opCmp(rhs); + } } // objects