www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19444] New: hasRawAliasing loops on class with static array,


          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) {
        return l;

DMD 2.081.2 correctly accepts and compiles this code. DMD 2.083.0 outputs these

Error: forward reference of variable hasRawAliasing
Error: template instance `std.traits.hasRawAliasing!(Thing).Impl!(Thing[2])`
error instantiating
       instantiated from here: hasRawAliasing!(Thing)
       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

            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.

Nov 28 2018