https://issues.dlang.org/show_bug.cgi?id=15851
Issue ID: 15851 Summary: Access violation when foreaching variadic template argument tuple Product: D Version: D2 Hardware: x86_64 URL: http://dlang.org/ OS: All Status: NEW Severity: normal Priority: P3 Component: dmd Assignee: nob...@puremagic.com Reporter: sunsp...@gmail.com The long description: Access violation when dereferencing a field in a foreach of a variadic template argument tuple, when inside a switch case. dmd is v2.070.2 from the official installer, and the machine is running Windows 8. ldc2 0.17.1 exhibits the same behaviour. Could not test gdc because of difficulty of installation. Reduced example (http://dpaste.dzfl.pl/ee9a4503f6f5): ----------------------- import std.stdio; version = broken; struct Foo { string abc; int def; } void walkArgumentTuple(T...)(ref T tup) { top: final switch (0) { foreach (i, ref thing; tup) { // thing is invalid for some reason // but the below doesn't fail assert(thing is tup[i]); case 0: version(broken) { // object.Error@(0): Access Violation writeln(thing); } else { // works writeln(tup[i]); } break top; } } } void main() { Foo f; walkArgumentTuple(f); } ----------------------- All tested compilers accept and compile this. It behaves differently depending on the number (and maybe type) of members of the Foo struct. Likewise if compiled with or without -m64, and whether parameters are marked as ref or not. In many combinations it won't error out, but instead spam the screen with garbage in hex. See the dpaste linked earlier, with version = dpastefreaksout uncommented. Foo(x"10 1C 00 00 00 00 00 00 7C FD 45 [... ad nauseam] I have also had it spout out semi-intelligible things removing ref from everything, but dpaste can't seem to reproduce that. Foo("\x04\x10\0\0\0\0\0\0gc.config\0src\\gc\\config.d\0\0\0\0\0", 0) --