www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15781] New: Type deduction const


          Issue ID: 15781
           Summary: Type deduction const
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: jbc.engelen gmail.com

struct TypeA {
    int value;

auto foo(T)(T start, T end) {
   import std.stdio;

void main() {
    alias Tiep = TypeA;
    const Tiep a;
    Tiep b;

    Tiep c = a;  // This is fine

    foo(a,b);    // This is not fine with DMD 2.069.2

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).

For `alias Tiep = int;` it compiles with DMD 2.070.2.
Also when modifying the code to read `auto foo(T)(const T start, const T end)`.

This issue was reported after a brief forum discussion:
http://forum.dlang.org/thread/pviqlkktqzeusjualhuk forum.dlang.org.

Mar 09 2016