[Issue 5363] const + alias this = wrong code

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Nov 13 02:36:58 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=5363


jens.k.mueller at gmx.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jens.k.mueller at gmx.de
         OS/Version|Windows                     |All
           Severity|critical                    |blocker


--- Comment #4 from jens.k.mueller at gmx.de 2012-11-13 02:36:38 PST ---
Today I ran into this bug. Unfortunately it tooks quite some time until I had a
minimal example that exemplified the problem. Then I could search the database
to find this report here.
I leave my minimal example here for reference.

struct A                                                                        
{                                                                               
    B b;                                                                        
    alias b this;                                                               
}                                                                               

struct B                                                                        
{                                                                               
    static struct Value                                                         
    {                                                                           
    }                                                                           
    Value value;                                                                

    B[] bs;                                                                     
    alias value this;                                                           

    bool opEquals(ref const B rhs) const // remove const in front of B and it
works
    {                                                                           
        return this.bs == rhs.bs;                                               
    }                                                                           
}                                                                               

unittest                                                                        
{                                                                               
    A a;                                                                        
    a.bs ~= B.init;                                                             
    B b;                                                                        
    b.bs ~= B.init;                                                             
    assert(b.opEquals(a)); // fails                                
}

This is Linux and dmd2.060.
This issue is a blocker for me because I can't use const and alias this
anymore. I have to remove the const which makes my code error-prone.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list