On Friday, 14 August 2015 at 06:44:53 UTC, ted wrote:
Hi,

(earlier posting on D.learn, but better test included here)...


dmd.2.067, dmd.2068 (64bit linux)


import std.container: SList;

void main()
{
    SList!int tmp=( 4 );
    SList!int tmp1;

    // Ensure tmp is empty
    tmp.removeAny();
    assert( tmp.empty == true );

    // Both tmp and tmp1 are empty
    // (however tmp1 is not internally initialised)
    tmp.insertAfter( tmp[], 3 );
//    tmp1.insertAfter( tmp1[], 3 );    <====== asserts here.

}

core.exception.AssertError@std/container/slist.d(57): Assertion failure

Changes in phobos mean that you cannot append to an _uninitialised_ empty singly linked list (you can, however, append to an _initialised_ empty linked list.....

bug ?

--ted

I can confirm that this is a bug but I'm not sure what the "correct" way is to fix it. SList creates a dummy node for the root of the list, but because structs don't allow default constructors, this dummy node is never allocated in the first case. Either we can add lots of null checks to initialize the list, or we can add this line:

@disable this();

Thoughts?

Reply via email to