From 5fb6afc2e1dba6a56c59440309bd6786296fba8e Mon Sep 17 00:00:00 2001 From: Eduard Staniloiu Date: Wed, 17 Apr 2019 00:03:54 +0300 Subject: [PATCH] Lower CmpExp between classes to __cmp call --- src/dmd/expressionsem.d | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/dmd/expressionsem.d b/src/dmd/expressionsem.d index 48e47cef2508..e4d394084c44 100644 --- a/src/dmd/expressionsem.d +++ b/src/dmd/expressionsem.d @@ -11333,6 +11333,24 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor return setError(); } + if (t1.ty == Tclass && t2.ty == Tclass) + { + // Lower to object.__cmp(e1, e2) + Expression cl = new IdentifierExp(exp.loc, Id.empty); + cl = new DotIdExp(exp.loc, cl, Id.object); + cl = new DotIdExp(exp.loc, cl, Id.__cmp); + cl = cl.expressionSemantic(sc); + + auto arguments = new Expressions(); + arguments.push(exp.e1); + arguments.push(exp.e2); + + cl = new CallExp(exp.loc, cl, arguments); + cl = new CmpExp(exp.op, exp.loc, cl, new IntegerExp(0)); + result = cl.expressionSemantic(sc); + return; + } + EXP cmpop; if (auto e = exp.op_overload(sc, &cmpop)) {