Bug 8819 – void static array should have init built-in propert

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-14T09:04:00Z
Last change time
2013-03-06T01:44:34Z
Keywords
pull
Assigned to
nobody
Creator
k.hara.pg

Comments

Comment #0 by k.hara.pg — 2012-10-14T09:04:24Z
Following code doesn't work with current dmd (2.060). void main() { alias void[1] T; auto vsa = T.init; } output: test.d(4): Error: void does not have a default initializer I think this is unnecessary restriction and almost a bug. An element of void[1] should have '0' as a default initializer.
Comment #1 by k.hara.pg — 2012-11-24T19:09:42Z
Comment #2 by bugzilla — 2012-12-03T18:07:49Z
I'm not convinced this is a good idea. void[] is supposed to be untyped data, and a 0 initializer is specific to some types, and not for others.
Comment #3 by k.hara.pg — 2012-12-03T19:32:30Z
(In reply to comment #2) > I'm not convinced this is a good idea. void[] is supposed to be untyped data, > and a 0 initializer is specific to some types, and not for others. In almost cases, void[] and void[n] are used to represent *bare* memory. Then, 0-initialized bare memory is enough acceptable concept to me. --- The enhancement only I argue is just to add init property. That means, default construction of void[n] should be kept invalid. void main() { void[1] vsa1 = (void[1]).init; // allowed by this enhancement void[1] vsa2; // default construction should still be error } I think void[n] should behave as like a struct has `@disable this();`. All structs have built-in `.init`. Therefore void[n] should also have `.init`. --- From a view of meta-programming, I think that all types which has run-time representation should have .init property. It is consistent and much useful. Example: template isSomeCheck(T) { enum isSomeCheck = is(typeof({ T t = T.init; // Can ignore T's constructing way. func(t); // check whether func accepts an lvalue object typed T func(T.init); // check whether func accepts an rvalue object typed T } } After taking this enhancement, only one type which doesn't have init property is void.
Comment #4 by k.hara.pg — 2012-12-04T16:55:24Z
In discussion here: https://github.com/D-Programming-Language/phobos/pull/842#issuecomment-9420485 Andrei asks why `defaultInit` is necessary, the answer is the lack of void[1].init.
Comment #5 by github-bugzilla — 2013-03-06T00:21:18Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/a4275e7847f553a3a2c038883612af7b68117ce3 fix Issue 8819 - void static array should have init built-in property https://github.com/D-Programming-Language/dmd/commit/c437fad3e8bc874ca8f1dcb0e77e8eb6488b5cf1 Merge pull request #1324 from 9rnsr/fix8819 Issue 8819 - void static array should have init built-in property