[Issue 14166] New: null dereference during CTFE

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Feb 10 07:00:21 PST 2015


https://issues.dlang.org/show_bug.cgi?id=14166

          Issue ID: 14166
           Summary: null dereference during CTFE
           Product: D
           Version: D1 & D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: regression
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: vlevenfeld at gmail.com

In the following code, I expect the pragma to output "int". When static if (1)
causes a null dereference in CTFE. Manually lowering (static if (0)) causes the
code to behave as expected.

/////

struct Proxy (T)
{
    T* ptr;

    ref deref ()
    {
        return *ptr;
    }

    alias deref this;
}

struct Test
{
    auto opIndex ()
    {
        return this;
    }
    auto opIndex (int)
    {
        return 1;
    }
}

template Elem (R)
{
    static if (0) // 0 => Elem == int; 1 => Error: dereference of null pointer
'this.ptr'
        alias Elem = typeof(R.init[][0]);
    else alias Elem = typeof(R.init[].opIndex (0));
}

void main ()
{
    alias T = Proxy!Test;
    pragma (msg, Elem!T);
}


/*
dmd git-HEAD outputs this:

source/app.d(11): Error: dereference of null pointer 'this.ptr'
source/app.d(31):        called from here: Proxy(null).deref()
source/app.d(37): Error: template instance app.Elem!(Proxy!(Test)) error
instantiating
source/app.d(37):        while evaluating pragma(msg, Elem!(Proxy!(Test)))
FAIL
.dub/build/application-debug-linux.posix-x86_64-dmd_2067-905D3FE7D130796D902AA401E263BCF6/
testing executable
Error executing command run:
dmd failed with exit code 1.

*/

--


More information about the Digitalmars-d-bugs mailing list