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


--- Comment #1 from Lukasz Wrzosek <luk.wrzosek gmail.com> 2012-02-14 14:31:59
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                   |


--- Comment #2 from Lukasz Wrzosek <luk.wrzosek gmail.com> 2012-02-14 14:34:36
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


--- Comment #3 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-02-04
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