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)
Comment #1 by moonlightsentinel — 2020-02-11T19:47:28Z
This no longer compiles:
onlineapp.d(14): Error: switch skips declaration of variable onlineapp.walkArgumentTuple!(Foo).walkArgumentTuple.thing at onlineapp.d(16)