www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16657] New: [The D Bug Tracker]


          Issue ID: 16657
           Summary: [The D Bug Tracker]
           Product: D
           Version: D2
          Hardware: All
               URL: http://dlang.org/
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: eyal weka.io

When adding an "alias this" to a type, the automatic opEquals and opCmp that
compare the object lexicographically are removed and instead only the alias
this portion of the type is compared via its opEquals/opCmp.

struct A {
    int x;

struct B {
    A a, b;
static assert(B(A(1), A(1)) != B(A(1), A(2))); // Works

struct C {
    A a, b;
    alias a this;
static assert(C(A(1), A(1)) != C(A(1), A(2))); // Fails!

Adding alias this should NOT cause a preference for the base type's

Nov 02 2016