incorrect data when returning static array in place of dynamic

sigod via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 10 14:32:26 PDT 2015


On Monday, 6 July 2015 at 10:20:28 UTC, anonymous wrote:
> On Monday, 6 July 2015 at 07:48:17 UTC, sigod wrote:
>> Aren't compiler smart enough to prevent it?
>>
>> ```
>> ubyte[] test1()
>> {
>> 	auto b = sha1Of("");
>>
>> 	return b; // Error: escaping reference to local b
>> }
>>
>> ubyte[] test2()
>> {
>> 	return sha1Of(""); // works, but returns incorrect data
>> }
>> ```
>>
>> Looks more like a bug to me.
>
> dmd 2.068.0 catches this. You can get the beta here:
> http://downloads.dlang.org/pre-releases/2.x/2.068.0/

That's good to know.


More information about the Digitalmars-d-learn mailing list