www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19950] New: access violation at compile time, possibly via


          Issue ID: 19950
           Summary: access violation at compile time, possibly via static
                    foreach and alias interaction
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: lakeavenger+dlangi gmail.com

The following snippet causes an access violation at compile time on dmd v2.086,
after a `test.d(2): Error: undefined identifier NotHere` error:

struct Bar {
    alias Baz = NotHere;

    static foreach (name; 0 .. 1) {
        alias someAlias = set!();

    void set()(Baz)
        if (true)

Changing any meaningful structure in the snippet, such as:

- removing the if guard in `set` (changing the condition seems fine)
- changing the arguments in `set`
- removing the static foreach (altering what it iterates over is fine, as long
as it's not empty)
- changing what `someAlias` aliases to

makes compilation act as normal (failing but no access violation), so I assume
this is a weird edge case with static foreach, if guards, and aliases.

Information DMD asked me to send:

DMD %.*s
predefs   DigitalMars Windows CRuntime_DigitalMars CppRuntime_DigitalMars
LittleEndian D_Version2 all D_InlineAsm D_InlineAsm_X86 X86 Win32 assert
D_ModuleInfo D_Exceptions D_TypeInfo D_HardFloat
binary    C:\D\dmd2\windows\bin\dmd.exe
version   v2.086.0

config    C:\D\dmd2\windows\bin\sc.ini
DFLAGS    -IC:\D\dmd2\windows\bin\..\..\src\phobos

run.dlang.io says the bug has been present ever since static foreach was
introduced, in dmd v2.076. Before that, the code obviously fails to parse.

Jun 10 2019