www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15851] New: Access violation when foreaching variadic


          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: nobody puremagic.com
          Reporter: sunspyre 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)
    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:
                    // object.Error (0): Access Violation
                    // works

                break top;

void main()
    Foo 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

    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)

Mar 30 2016