www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2929] New: Alias this when this is null

reply d-bugmail puremagic.com writes:
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 digitalmars.com
        ReportedBy: jason.james.house 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);
}


-- 
May 03 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2929


Lukasz Wrzosek <luk.wrzosek gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |luk.wrzosek gmail.com
         Resolution|                            |DUPLICATE



PST ---
*** This issue has been marked as a duplicate of issue 6777 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 14 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2929


Lukasz Wrzosek <luk.wrzosek gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|DUPLICATE                   |



PST ---
Sorry, it is not a duplicate ... :(

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 14 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2929


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |INVALID



18:17:14 PST ---
I don't understand this report. alias won't protect you from null references,
keeping references non-null is the programmer's responsibility.

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