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