Does slicing have an effect?

Max Haughton maxhaton at gmail.com
Sat May 25 20:50:30 UTC 2019


On Tuesday, 21 May 2019 at 20:31:58 UTC, Dennis wrote:
> I was replacing a memcpy with a slice assignment and 
> accidentally used == instead of =.
> Usually the compiler protects me from mistakes like that:
>
> ```
> int[4] a;
> a == a;
> ```
> Error: a == a has no effect
>
> However, because I was using slices it didn't:
> ```
> int[4] a;
> a[] == a[];
> ```
> No errors
>
> Does slicing have an effect I'm not aware of, or is this a bug?

It calls druntime( https://d.godbolt.org/z/3gS3-E ), so 
technically it does have an effect, even if that effect is 
completely unused and therefore optimized away. Whether this 
should be considered an effect or not is up to you


More information about the Digitalmars-d-learn mailing list