Bug 17343 – class.init.<symbol> does not working

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-04-23T09:36:00Z
Last change time
2017-04-23T09:51:43Z
Assigned to
nobody
Creator
andrey

Comments

Comment #0 by andrey — 2017-04-23T09:36:45Z
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 by ag0aep6g — 2017-04-23T09:48:19Z
(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 by andrey — 2017-04-23T09:51:43Z
ok got it.