Deduction regression or improvement?

Hara Kenji via Digitalmars-d digitalmars-d at puremagic.com
Fri Mar 11 05:28:22 PST 2016


On Wednesday, 9 March 2016 at 01:27:41 UTC, Dicebot wrote:
>
> Looks like regression to me.
>
> If SomeStruct contains indirections, it should be able to 
> deduce T as
> const(SomeStruct).
>
> It SomeStruct is strict value type, deducing T as both 
> SomeStruct and const(SomeStruct) would be fine.

But the behavior with 2.068 was bug-prone.

struct S
{
     int value;
}

auto foo(T)(T start, T end)
{
     pragma(msg, "In foo, T = ", T);
}

void main()
{
     const S cs;
     S ms;

     foo(cs, ms);    // [a] NG with 2.069.2, but T == S with 2.068!
     foo(ms, cs);    // [b] NG with 2.069.2, but T == const(S) 
with 2.068!!
}

The both cases are disabled in the bugfix PR:
https://github.com/D-Programming-Language/dmd/pull/4818

I think that T should be deduced to the typeof(true ? cs : ms) at 
line [a] and typeof(true ? ms : cs) at line [b], then the two 
lines will get consistent deduction result T == const(S).

Kenji Hara


More information about the Digitalmars-d mailing list