www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20704] New: `-preview=rvaluerefparam`

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

          Issue ID: 20704
           Summary: `-preview=rvaluerefparam`
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: industry
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: pro.mathias.lang gmail.com

Consider the following code:
```
void foo (T) (const auto ref T arg = T.init) {}
void bar (T) (const      ref T arg = T.init) {}

void main ()
{
    int i;
    foo!int();
    bar!int(i);
}
```

This will produce the following error message:
```
autoref.d(2): Error: cannot modify constant `0`
autoref.d(8): Error: template instance `autoref.bar!int` error instantiating
```

Compiled with or without `-preview=rvaluerefparam`, DMD 2.091.

Now there's a few problem with this:
1) The error message is wrong: there's no modification taking place, the
parameter is `const`;
2) It should work with the `-preview` switch;
3) Should the error message happens if the default parameter is not used ? It
triggers on the definition ATM.

--
Mar 29