What's the deal with "Warning: explicit element-wise assignment..."

Benjamin Thaut via Digitalmars-d digitalmars-d at puremagic.com
Tue Apr 15 05:55:22 PDT 2014


Am 15.04.2014 11:18, schrieb bearophile:
> Andrei Alexandrescu:
>
>> We've just enabled warnings as errors in our build system at work and
>> suddenly:
>
> It's much better to enable warnings since day -1, that means the day
> before you start creating your D project.
> That's why I'd like D compilers to have warnings active on default and
> to have a switch to disable them on request (Walter has not yet answered
> about this idea).
>
>
>> What's the idea?
>
> The idea is to tell well apart the assignment of values (like scalars
> and fixed size arrays) from slice assignments. In general if you have a
> vector operation, use a []. There are corner cases (with arrays of
> arrays, fixed sized arrays of dynamic arrays, etc), that if you don't
> use such strict syntax, lead to undefined (ambiguous, weird) situations.
> The warning helps avoid that problem, and the warning will be replaced
> by a deprecation later.
>
> Bye,
> bearophile

It was a error once, but many situations were not detected correctly. So 
I hope before it becomes deprecated, it should first be properly working.

One example for a situation that did not work correctly:

struct MyArray
{
   int[] opSlice() { ... }
}

void someFunc()
{
   MyArray a;
   int[] b;
   b[] = a[]; // <- problem here. compiler wants you to write b[] = a[][]
}


More information about the Digitalmars-d mailing list