Bug 11975 – Compile time error on null dereference
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-01-22T22:04:00Z
Last change time
2014-01-23T08:13:19Z
Assigned to
nobody
Creator
sumit.adhikari
Comments
Comment #0 by sumit.adhikari — 2014-01-22T22:04:36Z
Following code leads to segmentation fault:
abstract class foo_base(T)
{
private T bro ;
public void zoo(T bro_) {
bro = bro_ ;
}
}
class foo(T) : foo_base!(T)
{
}
void main()
{
foo!double Foo ;
Foo.zoo(1.0);
}
Comment #1 by sumit.adhikari — 2014-01-22T22:05:54Z
This is a blocker for current development. Please take a look at it as soon as possible.
Comment #2 by k.hara.pg — 2014-01-22T22:38:37Z
(In reply to comment #0)
> Following code leads to segmentation fault:
>
> void main()
> {
>
> foo!double Foo ;
> Foo.zoo(1.0);
>
> }
You're call instance method 'zoo' on null object reference.
void main()
{
foo!double Foo;
assert(Foo is null); // !
Foo.zoo(1.0); // Segfault
}
To me the segfault looks intended result.
Comment #3 by sumit.adhikari — 2014-01-22T22:51:05Z
Why is the compiler not able to tell me the problem and I need to go through a segfault ?
Regards, Sumit
Comment #4 by yebblies — 2014-01-22T23:18:50Z
(In reply to comment #3)
> Why is the compiler not able to tell me the problem and I need to go through a
> segfault ?
>
> Regards, Sumit
The analysis to detect this has not been implemented, and there is some question as to whether it is worth implementing given how easy it is to identify the source of the segfault in a debugger.
It will actually detect this simple case if you compile with -O.
Comment #5 by ibuclaw — 2014-01-23T00:10:24Z
(In reply to comment #0)
> Following code leads to segmentation fault:
>
>
> abstract class foo_base(T)
It looks like your treating a class as if it is equivalent to C++?
An error on null dereference is a bit of a problem as it could potential be more breaking than good. Not to mention all the cases that we can't catch.
---
shared MyClass foo;
/* 'foo' gets initialised by another thread in the meantime...
Or at least so we expect. :)
*/
foo.bar(); // BOOM!
Comment #6 by andrej.mitrovich — 2014-01-23T08:13:19Z
*** This issue has been marked as a duplicate of issue 4595 ***