crash when using &this in struct constructor
baz
b2.temp at gmx.com
Wed Jul 18 11:35:40 UTC 2018
On Wednesday, 18 July 2018 at 11:27:33 UTC, baz at dlang-community
wrote:
> On Monday, 16 July 2018 at 22:21:12 UTC, H. S. Teoh wrote:
>> On Mon, Jul 16, 2018 at 10:08:34PM +0000, Eric via
>> Digitalmars-d-learn wrote:
>>> [...]
>>
>> It's not illegal per se, but a very, very bad idea in general,
>> because in D, structs are expected to be int-like POD values
>> that can be freely copied/moved around by the compiler. More
>> specifically, when structs are passed into functions or
>> returned from functions, they may be moved around. Which
>> means internal pointers will wind up being wrong.
>>
>> [...]
>
> Moving doesn't seem to be the issue here. Despite of the ICE,
> this code shouldn't compile, unless "&this" is allowed at
> compile-time.
still with .init() trick this works, so im' not super sure...
More information about the Digitalmars-d-learn
mailing list