[Issue 2929] New: Alias this when this is null

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun May 3 12:59:39 PDT 2009


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

           Summary: Alias this when this is null
           Product: D
           Version: 2.029
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: jason.james.house at gmail.com


The code below should demonstrate the problem.  The implicit use of alias this
is not null-aware.  That means that a nullable class reference with alias this
to another reference type is used, then segfaults will occur.  The only
workaround is to define an intermediate variable and test for null before
relying on the implicit alias to work.  This kind of kills the utility of alias
this.

class A{}
class B{
  private A a;
  A foo(){ return a; }
  alias foo this;
}

void main(){
  B b;
  A a = b; // seg fault
  assert(a is null);
}


-- 



More information about the Digitalmars-d-bugs mailing list