digitalmars.D.bugs - [Issue 21884] New: [betterC] can't compare arrays with -betterC
- d-bugmail puremagic.com (42/42) Apr 30 2021 https://issues.dlang.org/show_bug.cgi?id=21884
https://issues.dlang.org/show_bug.cgi?id=21884 Issue ID: 21884 Summary: [betterC] can't compare arrays with -betterC Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: minor Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: blatblatnik gmail.com Without -betterC, the following code compiles: bool fine() { float[2] a; return a == a; } It does exactly what you'd expect, and I'm happy. With -betterC however: bool error() { float[2] a; return a == a; // Error: `TypeInfo` cannot be used with -betterC. } I don't know why dmd needs to emit type info for array comparisons. The type is clearly known at compile time. I don't see why this wouldn't be possible in -betterC. By itself, this wouldn't be a massive issue, because we can also do bool fine() { float[2] a; return a[] == a[]; } And now this will compile and work as expected in -betterC. In fact I even prefer this syntax personally since it's more consistent with other array operations. But this doesn't work for multi-dimensional arrays. bool error() { float[2][2] a; return a == a; // Error: `TypeInfo` cannot be used with -betterC. return a[] == a[]; // Error: `TypeInfo` cannot be used with -betterC. } And it definitely should work - at least one of these should work. --
Apr 30 2021