[Issue 15408] S.init for struct containing member field with array literal initializer fails @nogc
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Aug 3 01:29:32 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=15408
Steven Schveighoffer <schveiguy at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |spec, wrong-code
CC| |schveiguy at gmail.com
OS|Mac OS X |All
Severity|normal |major
--- Comment #1 from Steven Schveighoffer <schveiguy at gmail.com> ---
This reduces in AST to:
```d
S s = S([42]);
```
Which is why it always allocates.
This also defies the spec, which states:
> .init produces a constant expression that is the default initializer.
This is not a constant expression.
This also leads to such puzzles as `assert(S.init !is S.init)`
Also note that:
```d
S s;
```
Does *not* produce an allocation.
S.init should not allocate. Neither should S()
--
More information about the Digitalmars-d-bugs
mailing list