[Issue 16235] New: type of conditional expression (ternary operator) is widened when operands differ in constness
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Jul 4 11:59:54 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16235
Issue ID: 16235
Summary: type of conditional expression (ternary operator) is
widened when operands differ in constness
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: ag0aep6g at gmail.com
These pass:
----
static assert(is(typeof(true ? int.init : int.init) == int));
static assert(is(typeof(true ? int.init : const(int).init) == int));
static assert(is(typeof(true ? byte.init : byte.init) == byte));
----
This one fails but should pass:
----
static assert(is(typeof(true ? byte.init : const(byte).init) == byte));
----
This makes CommonType!(byte, const byte) evaluate to int. And that makes this
little program surprisingly fail compilation:
----
void main()
{
import std.range: chain;
ubyte[] a = [1, 2];
const(ubyte)[] b = [3, 4];
ubyte f = chain(a, b).front; /* Error: cannot implicitly convert expression
(chain(a, b).front()) of type int to ubyte */
}
----
--
More information about the Digitalmars-d-bugs
mailing list