www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10858] New: [CTFE] null pointer assert error

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: monarchdodra gmail.com



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: -------
Aug 20 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10858


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[CTFE] null pointer assert  |CTFE wrong code for
                   |error                       |comparison of array of
                   |                            |pointers



This is a horrible wrong-code bug, nothing to do with 'new'. The bug is in ==.
The pointer doesn't need to be null.
Reduced test case:

bool bug10858()
{
    int *[4] x;
    x[0] = null;
    assert(x[0] == null);
    return true;
}
static assert(bug10858());

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 05 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10858




Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/77e471b8355c433cbfa5cd3a8264a4740bafdaa2
Fix issue 10858 CTFE wrong array of pointers

Pointer comparison should be based on rvalues, not lvalues.
That bug was also hiding three latent wrong-code bugs.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 09 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10858




Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/9544863a6491feeaa9c6c0ee8094b0c49ba385f7
Fix issue 10858 CTFE wrong array of pointers

Pointer comparison should be based on rvalues, not lvalues.
That bug was also hiding two latent wrong-code bugs.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 13 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10858


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
            Version|D2                          |D1 & D2
         Resolution|                            |FIXED


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