July 30 [Issue 24688] New: Parameter by-value keeps const (only in templates) | ||||
---|---|---|---|---|
| ||||
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@puremagic.com Reporter: dominikus@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. -- |
Copyright © 1999-2021 by the D Language Foundation