[Issue 21209] New: scope attribute inference with does not work well with foreach
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Aug 29 13:50:33 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=21209
Issue ID: 21209
Summary: scope attribute inference with does not work well with
foreach
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: rightfold+bugzilla+dlang at gmail.com
The following program does not compile:
---
$ cat main.d
void foo()(const(char)[] cs)
{
foreach (c; cs)
bar(c);
}
@safe
void bar(char c)
{
}
@safe
void main()
{
char[10] cs;
foo(cs); // line 16
}
$ dmd -dip1000 main.d
main.d(16): Error: reference to local variable `cs` assigned to non-scope
parameter `cs` calling example.foo!().foo
---
By manually adding the scope attribute to the cs parameter, the program
compiles. But it is expected that DMD infers this from the body of the foo
function, as it is a template.
Verified with DMD 2.092.0 and LDC 1.23.0.
--
More information about the Digitalmars-d-bugs
mailing list