November 28, 2018
https://issues.dlang.org/show_bug.cgi?id=19444

          Issue ID: 19444
           Summary: hasRawAliasing loops on class with static array,
                    cannot swap class refs
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: regression
          Priority: P1
         Component: phobos
          Assignee: nobody@puremagic.com
          Reporter: kirsybuu@gmail.com

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.

--