[Issue 21884] [betterC] can't compare arrays with -betterC

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Apr 30 20:50:13 UTC 2021


--- Comment #2 from Blatnik <blatblatnik at gmail.com> ---
It also seems like the fixed size array comparisons (type[N] == type[N]) are
implemented internally in DMD. However slice comparisons (type[N][] ==
type[N][]) are implemented in the runtime.

The compiler converts

float[2][2] a;
bool b = a[] == b[];


float[2][2] a;
bool b = core.internal.array.equality.__equals!(float[2], float[2])(a[], a[]);

And this __equals template is something we can change very easily without
digging through the compiler.

The offending lines in this function effectively try to do:

foreach(i; 0 .. a.length)
  if (a[i] != a[i])
    return false;
return true;

But a[i] is a float[2], which can't be compared in -betterC..

If we had a special case for arrays that did this instead

foreach(i; 0 .. a.length)
  if (a[i][] != a[i][])
    return false;
return true;

Then at least type[N][] == type[N][] would work, until a better fix was found
for type[N] == type[N].


More information about the Digitalmars-d-bugs mailing list