Christophe Travert <> changed:

           What    |Removed                     |Added
                 CC|                            |christophe.travert@normales
                   |                            |

--- Comment #4 from Christophe Travert <> 
2012-07-18 06:46:14 PDT ---
(In reply to comment #3)
> The reason for the failure is that for
> arr2D[0].insert(1);
> the opIndex() method is invoked which returns by value. In theory this is okay
> since the array is stored by reference and the returned value contains a
> reference to the payload data of the inner array.
> What happens here is that arr2D[0] is uninitialized (the pointer to the
> RefCounted object is null) and this guy is returned. It is then changed (the
> insert method initializes the temporary and creates the ref-counted object 
> with
> the inserted content).
> One way to resolve this is to make opIndex return a reference. Or is there an
> alternative?

I think both should be corrected:
 - uninitialised Arrays do not behave as reference values: you can copy them,
change the copy, and this does not affect the original. This breaks the
intended 'reference value' behavior. The cost of creating a payload for each
empty Array may be compensated by not having to check the payload is
initialised in each of Array's methods.
 - opIndex should return a reference. Any struct with a non-const method will
suffer the same problem when 'array[i].method' is called: the method is called
on a copy of the contained data.

Note that Array!bool cannot return a reference to a bool, and can't be
corrected the same way. I think this is not a problem, but I may miss

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to