Bug 2929 – Alias this when this is null

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2009-05-03T14:59:00Z
Last change time
2013-11-09T05:55:46Z
Assigned to
nobody
Creator
jason.james.house

Comments

Comment #0 by jason.james.house — 2009-05-03T14:59:50Z
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); }
Comment #1 by luk.wrzosek — 2012-02-14T14:31:59Z
*** This issue has been marked as a duplicate of issue 6777 ***
Comment #2 by luk.wrzosek — 2012-02-14T14:34:36Z
Sorry, it is not a duplicate ... :(
Comment #3 by andrej.mitrovich — 2013-02-04T18:17:14Z
I don't understand this report. alias won't protect you from null references, keeping references non-null is the programmer's responsibility.
Comment #4 by verylonglogin.reg — 2013-11-09T05:55:46Z
Filed enhancement request Issue 11482 based on this one.