[Issue 15781] [REG2.069] Template type deduction failure with same-type variables with different constness

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Mar 15 05:25:28 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=15781

Kenji Hara <k.hara.pg at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
            Summary|Template type deduction     |[REG2.069] Template type
                   |failure with same-type      |deduction failure with
                   |variables with different    |same-type variables with
                   |constness                   |different constness

--- Comment #2 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to Johan Engelen from comment #0)
> The code compiles fine with DMD 2.068.2.
> The code fails to compile with DMD 2.068.2 and DMD 2.070.2:
> deduce.d(19): Error: template deduce.foo cannot deduce function from
> argument types !()(const(TypeA), TypeA), candidates are:
> deduce.d(5):        deduce.foo(T)(T start, T end)
> 
> I believe this is a regression.
> DMD 2.068.2 deduces T = TypeA (non-const).

This is a rejects-valid issue from 2.069, so is a regression. But, the behavior
in 2.068 -- T is deduced to TypeA (non-const) -- is not intentional result,
because there was order-dependent bug.

struct S
{
    int value;
}

void foo(T)(T a, T b)
{
    pragma(msg, T);
}

void main()
{
    const S cs;
          S ms;
    foo(cs, ms);    // prints 'S'
    foo(ms, cs);    // prints 'const(S)', inconsistent!
}

Therefore, from the built-in common type calculation mechanism, the T should be
deduced to const(S) independent from the order of function arguments.

--


More information about the Digitalmars-d-bugs mailing list