Bug 2995 – Incorrect conversion in c ? a : b

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2009-05-16T21:41:00Z
Last change time
2014-02-15T02:46:17Z
Keywords
patch, wrong-code
Assigned to
nobody
Creator
andrei

Comments

Comment #0 by andrei — 2009-05-16T21:41:20Z
class A {} void main() { immutable(A) b; A c; auto z = true ? b : c; writeln(typeof(z).stringof); } writes Object, which is wrong in a number of ways. The common type of A and immutable(A) is const(A).
Comment #1 by clugdbug — 2010-04-04T08:22:46Z
PATCH: cast.c, line 1663. Conversion of both types to const needs to occur for classes, as well as for arrays and pointers. else if (t1->ty == Tclass || t2->ty == Tclass) { + if (t1->mod != t2->mod) + { + t1 = t1->mutableOf()->constOf(); + t2 = t2->mutableOf()->constOf(); + t = t1; + goto Lagain; + } while (1) { int i1 = e2->implicitConvTo(t1); int i2 = e1->implicitConvTo(t2);
Comment #2 by clugdbug — 2010-05-05T19:19:37Z
Fixed DMD2.044.