www.fgks.org   »   [go: up one dir, main page]

Issue 20704 - `-preview=rvaluerefparam` does not work with `init` as default parameter
Summary: `-preview=rvaluerefparam` does not work with `init` as default parameter
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: industry, pull
Depends on:
Blocks:
 
Reported: 2020-03-29 10:09 UTC by Mathias LANG
Modified: 2021-04-12 06:49 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Mathias LANG 2020-03-29 10:09:30 UTC
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.
Comment 1 Dlang Bot 2021-04-09 13:56:07 UTC
@nordlow created dlang/dmd pull request #12413 "Fix issue 20704" fixing this issue:

- Fix issue 20704

https://github.com/dlang/dmd/pull/12413
Comment 2 Dlang Bot 2021-04-12 06:49:56 UTC
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