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.
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.