[Issue 24499] New: foreach over a ref parameter to an rvalue should be an error
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Apr 13 18:30:02 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24499
Issue ID: 24499
Summary: foreach over a ref parameter to an rvalue should be an
error
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: bugzilla at digitalmars.com
This should fail to compile:
@safe void test()
{
foreach(ref el; 0 .. 5) el = 42;
}
It doesn't make any sense, and generates bad code:
0000: 55 push RBP
0001: 48 8B EC mov RBP,RSP
0004: 48 83 EC 10 sub RSP,010h
0008: C7 45 F8 00 00 00 00 mov dword ptr -8[RBP],0
000f: C7 45 FC 05 00 00 00 mov dword ptr -4[RBP],5
0016: 8B 45 F8 mov EAX,-8[RBP]
0019: 3B 45 FC cmp EAX,-4[RBP]
001c: 7D 0C jge L2a
001e: C7 45 F8 2A 00 00 00 mov dword ptr -8[RBP],02Ah !!!!!
0025: FF 45 F8 inc dword ptr -8[RBP]
0028: EB EC jmp short L16
002a: C9 leave
002b: C3 ret
--
More information about the Digitalmars-d-bugs
mailing list