Bug 6940 – immutable(int*)*/immutable(int)** and int** do not combine

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-11-12T13:34:00Z
Last change time
2011-12-20T13:03:08Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
timon.gehr

Comments

Comment #0 by timon.gehr — 2011-11-12T13:34:54Z
immutable(int*)* and int** do not combine even though const(int*)* would be a common type: immutable(int*)* x; int** y; static assert(is(typeof(x) : const(int*)*)); // ok static assert(is(typeof(y) : const(int*)*)); // ok static assert(is(typeof(1?x:y))); // fail Compare to dynamic arrays: immutable(int[])[] a; int[][] b; static assert(is(typeof(a) : const(int[])[])); // ok static assert(is(typeof(b) : const(int[])[])); // ok static assert(is(typeof(1?a:b))); // ok (why on earth do the two cases use different logic?) Therefore the following could be used as a workaround: static assert(is(typeof((1?x[0..1]:y[0..1]).ptr)));
Comment #1 by k.hara.pg — 2011-11-16T19:44:01Z
> static assert(is(typeof(x) : const(int*)*)); // ok > static assert(is(typeof(a) : const(int[])[])); // ok I think these two lines should not compile. They are the part of bug 4251. Then, Both two cases should not have common type, IMO.
Comment #2 by timon.gehr — 2011-11-17T11:40:16Z
(In reply to comment #1) > > static assert(is(typeof(x) : const(int*)*)); // ok > > > static assert(is(typeof(a) : const(int[])[])); // ok > > I think these two lines should not compile. > They are the part of bug 4251. > > Then, Both two cases should not have common type, IMO. No, they are not part of bug 4251. This bug report is valid. This is bug 4251: immutable(int)** x; immutable(int)[][] y; static assert(is(typeof(x): const(int)**)); static assert(is(typeof(y): const(int)[][])); Consider this: immutable(int)** x; int y; // we now make *x point to y, even though y is not immutable: const(int)** p = x; // bug 4251 *p=&y; // since p == x, this assigns &y to *x That only works because immutable converted to const _two references deep_. None of that is going on here, consider this: immutable(int*)* x int y; // we now try to do the same thing const(int*)* p = x; // assume this works *p = y; // error!
Comment #3 by timon.gehr — 2011-11-18T13:35:48Z
immutable(int)** and int** should also combine to const(int*)*
Comment #4 by k.hara.pg — 2011-12-19T07:11:36Z
Comment #5 by bugzilla — 2011-12-20T13:03:08Z