[Issue 10858] New: [CTFE] null pointer assert error

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 20 03:45:56 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10858

           Summary: [CTFE] null pointer assert error
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: monarchdodra at gmail.com


--- Comment #0 from monarchdodra at gmail.com 2013-08-20 03:45:53 PDT ---
Apparently, CTFE cannot interpret "new int*" at compile time. However, it can
(!?) interpret new int*[](1)?

However, depending on the context, it may actually no correctly evaluate it:

//----
auto foo1(T)()
{
    return new T;
}
auto foo2(T)()
{
    return new T[](1);
}

void main()
{
    //foo1 tests.
    version (none) {
        bool dg1()
        {
            auto a = foo1!(int*)(); //Fails here.
            assert(a == null);
            return true;
        }
        enum a = foo1!(int*)(); //Fails
        static assert(dg1()); //Also fails.
    }

    //foo2 tests
    {
        bool dg2()
        {
            auto a = foo2!(int*)(); //OK?
            assert(a[0] == null); //Fails here ???
            return true;
        }
        enum a = foo2!(int*)(); //OK
        static assert(a[0] == null); //OK
        static assert(dg2()); //FAILS.
    }
}
//----

In this example (the "foo2" tests), we can see that "enum a = foo2!(int*)()" is
perfectly evaluated. The "static assert" afterwards proves it.

However, if these two instructions are instead evaluated with CTFE "static
assert(dg2())", then "something" will fail...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list