D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17343 - class.init.<symbol> does not working
Summary: class.init.<symbol> does not working
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-04-23 09:36 UTC by Andrey
Modified: 2017-04-23 09:51 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrey 2017-04-23 09:36:45 UTC
Can't get default value for symbol in class, if I write this working well:
> struct A {
>     int a = 10;
> }
>
> assert(A.init.a == 10);

But if change struct to class, application will crush
> class B {
>     int b = 10;
> }
>
> assert(B.init.b == 10); // exited abnormally with code 2
Comment 1 ag0aep6g 2017-04-23 09:48:19 UTC
(In reply to Andrey from comment #0)
> > class B {
> >     int b = 10;
> > }
> >
> > assert(B.init.b == 10); // exited abnormally with code 2

This works as expected. `B.init` is null. When you dereference null the program will crash because it's not allowed to read from there. An error message might say "segmentation fault" or "access violation".

I'm closing this as invalid. Please post to the learn group in the forum if you have questions about this. http://forum.dlang.org/group/learn
Comment 2 Andrey 2017-04-23 09:51:43 UTC
ok got it.