www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - shared and idup

reply "Low Functioning" <nathan.judge gmail.com> writes:
shared int[] foo;
auto bar() {
	foo ~= 42;
	return foo.idup;
}
Error: cannot implicitly convert element type shared(int) to 
immutable in foo.idup

Is this not correct? If I instead dup'd an array of ints (or some 
other non-reference elements) and cast to immutable, would I be 
in danger of undefined behavior?
Aug 19 2014
parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Tuesday, 19 August 2014 at 17:56:31 UTC, Low Functioning wrote:
 shared int[] foo;
 auto bar() {
 	foo ~= 42;
 	return foo.idup;
 }
 Error: cannot implicitly convert element type shared(int) to 
 immutable in foo.idup

 Is this not correct? If I instead dup'd an array of ints (or 
 some other non-reference elements) and cast to immutable, would 
 I be in danger of undefined behavior?
Try upgrading you compiler to the just released 2.067, it works for me with that version.
Aug 19 2014
parent "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Tuesday, 19 August 2014 at 19:00:49 UTC, Marc Sch├╝tz wrote:
 On Tuesday, 19 August 2014 at 17:56:31 UTC, Low Functioning 
 wrote:
 shared int[] foo;
 auto bar() {
 	foo ~= 42;
 	return foo.idup;
 }
 Error: cannot implicitly convert element type shared(int) to 
 immutable in foo.idup

 Is this not correct? If I instead dup'd an array of ints (or 
 some other non-reference elements) and cast to immutable, 
 would I be in danger of undefined behavior?
Try upgrading you compiler to the just released 2.067, it works for me with that version.
Actually, it's 2.066, but regardless, dup and idup were turned into free functions, so that will probably fix some bugs where they didn't work with shared or weren't nothrow or somesuch (or if it doesn't, it puts them one step closer to it). - Jonathan M Davis
Aug 19 2014