Bug 20704 – `-preview=rvaluerefparam` does not work with `init` as default parameter
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-03-29T10:09:30Z
Last change time
2021-04-12T06:49:56Z
Keywords
industry, pull
Assigned to
No Owner
Creator
Mathias LANG
Comments
Comment #0 by pro.mathias.lang — 2020-03-29T10:09:30Z
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.
dlang/dmd pull request #12413 "Fix issue 20704 - -preview=rvaluerefparam does not work with init as default parameter" was merged into master:
- 9a2042425a1e3161012f34b1c140c3a7d41b849a by nordlow:
Fix issue 20704
https://github.com/dlang/dmd/pull/12413