[Issue 12360] New: struct field not actually updated

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 13 19:58:16 PDT 2014


https://d.puremagic.com/issues/show_bug.cgi?id=12360

           Summary: struct field not actually updated
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: lionel.thiry at gmail.com


--- Comment #0 from Lionel Thiry <lionel.thiry at gmail.com> 2014-03-13 19:58:11 PDT ---
I was testing dmd 2.065 with some old work of mine and came upon this bug. I've
tried my best to reduce it to this (first time ever I post a bug report, sorry
if I don't do it the right way):

struct BufferedArray(/*of*/T) {
    T[] m_array;
    uint index=0;
    this( T[] array ) { m_array = array; }
}

void push(T)( T Element, /*on*/BufferedArray!(T) array ) {
    array.m_array[array.index] = Element;
    array.index++;
}

unittest {
    auto test_array = BufferedArray!(/*of*/string)( new string[10] );

    push( "Hello", test_array );
    push( "world", test_array );
    push( "!", test_array );

    assert( test_array.index == 3 ); //fails
}

As the bug was particulary unclear to me, I inserted a bunch of writeln's which
clearly show that index is updated inside the push function but as soon as push
exits, index is zero again. The field is not actually updated.

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


More information about the Digitalmars-d-bugs mailing list