[Issue 10108] Thread local slice to array literal references the same data

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri May 17 15:26:27 PDT 2013


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



--- Comment #9 from Simen Kjaeraas <simen.kjaras at gmail.com> 2013-05-17 15:26:26 PDT ---
I see. Once again, simplified:

import core.thread;

struct Foo {
    int[] arr;
}

Foo[] arr = [Foo([1,2,3])]; // Should have failed? (1)

void main( ) {
    int* p = arr[0].arr.ptr;
    auto thr = new Thread({assert(arr[0].arr.ptr == p);}); // Should have
failed. (2)
    thr.start();
    thr.join();
}

In this case, for the assert to fail, we'd have to deep-dup the array (COW
might make that unnecessary, but that's beside the point).

This is in a way related to the issue of array literals being mutable, in that
it is an example of the compiler erroneously assuming some state may be shared
when in fact it shouldn't.

I contend that (1) above should simply not compile. It should be required to be
placed in a module constructor instead. A case can be made that the compiler
should automagically place it in a module constructor for you, but I am not of
that opinion.

-- 
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