[Issue 24688] New: Parameter by-value keeps const (only in templates)
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Jul 30 05:36:01 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24688
Issue ID: 24688
Summary: Parameter by-value keeps const (only in templates)
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: dominikus at scherkl.de
```d
int fun(int x) { return ++x; }
T tpl(T)(T x) { return ++x; }
main
{
const int i = 1;
const range r; // some type that cannot create mutable copies
int z = i; // works, the compiler makes a mutable copy
range s = r; // error **
z = fun(i); // works, the compiler makes a mutable copy
z = tpl(i); // error
}
```
The compiler should at least try to make a mutable copy also for templates.
If that is not possible, it should give the same error as in the line with **.
I'm ok if it instead tries a constant copy, but that should not be the default.
--
More information about the Digitalmars-d-bugs
mailing list