Bug 19444 – hasRawAliasing loops on class with static array, cannot swap class refs

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2018-11-28T21:50:18Z
Last change time
2018-12-05T00:19:02Z
Assigned to
Stanislav Blinov
Creator
kirsybuu

Comments

Comment #0 by kirsybuu — 2018-11-28T21:50:18Z
The following code used to work but now fails to compile: import std.algorithm : swap; class Thing { Thing[2] child; this() { } static Thing bug(Thing l, Thing r) { swap(l,r); return l; } } DMD 2.081.2 correctly accepts and compiles this code. DMD 2.083.0 outputs these errors: /home/kirsybuu/.dvm/compilers/dmd-2.083.0/linux/bin/../../src/phobos/std/traits.d(2890): Error: forward reference of variable hasRawAliasing /home/kirsybuu/.dvm/compilers/dmd-2.083.0/linux/bin/../../src/phobos/std/traits.d(2902): Error: template instance `std.traits.hasRawAliasing!(Thing).Impl!(Thing[2])` error instantiating /home/kirsybuu/.dvm/compilers/dmd-2.083.0/linux/bin/../../src/phobos/std/traits.d(3233): instantiated from here: hasRawAliasing!(Thing) /home/kirsybuu/.dvm/compilers/dmd-2.083.0/linux/bin/../../src/phobos/std/algorithm/mutation.d(2744): instantiated from here: hasAliasing!(Thing) swap_hasRawAliasing.d(6): instantiated from here: swap!(Thing) Failed: ["/home/kirsybuu/.dvm/compilers/dmd-2.083.0/linux/bin/dmd", "-v", "-o-", "swap_hasRawAliasing.d", "-I."] The only code in the backtrace that seems to be different between versions is hasRawAliasing, which added the following case that is causing a recursive loop: else static if (is(T[0] foo : U[N], U, size_t N)) enum has = hasRawAliasing!U; Also, given that I just want to swap two class references, I would expect them to be handled similarly to pointers: changing Thing to a struct and l/r to Thing* makes DMD 2.083.0 accept the code.
Comment #1 by stanislav.blinov — 2018-11-29T16:20:58Z
Comment #2 by github-bugzilla — 2018-12-05T00:19:01Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/43545feff89de12b77d5c489b93a805dc2a77a50 Fix Issue 19444. https://github.com/dlang/phobos/commit/807afdc85ea77ada608b36f8d0852f9728531b1b Merge pull request #6784 from radcapricorn/fix19444 Fix Issue 19444: hasRawAliasing loops on class with static array