bug?

deed via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 15 11:15:52 PDT 2016


On Thursday, 15 September 2016 at 14:42:13 UTC, Jonathan M Davis 
wrote:
> On Thursday, September 15, 2016 14:07:18 deed via 
> Digitalmars-d-learn wrote:
>> On Thursday, 15 September 2016 at 13:57:13 UTC, rikki 
>> cattermole
>>
>> wrote:
>> > Not a bug, it is never used.
>>
>> I'd expect an "Error: ... no effect ..." from the compiler.
>
> That would only work in fairly simplistic cases. For instance, 
> if you were allocating an array of structs instead of an array 
> of ints, then it _could_ have an effect. So, it's not an error 
> that would catch much. And it's not like the code is doing 
> anything illegal - just useless, which is why it gets optimized 
> out.
>
> - Jonathan M Davis

I dont't feel strongly about this at all, it was just my first 
reaction that it was a meaningless statement that the compiler 
should warn about or give an error on.

I'm curious when you would need to do only `new Struct[](1000);` 
instead of
`auto structs = new Struct[](1000);`?

In case it was not clear, the code was:
char[] str;
// ...
str.length = ...
str[i] = ...

and was intended to be updated to:
char[] str = new char[](len);
// ...
str[i] = ...

but somehow the line ended up as
char[] str; new char[](len);
// ..
str[i] = ... // oops.


More information about the Digitalmars-d-learn mailing list