Instantiation of nested structs should be allowed outside their parent scope

Stanislav Blinov stanislav.blinov at gmail.com
Tue Nov 9 15:59:58 UTC 2021


On Tuesday, 9 November 2021 at 15:55:14 UTC, Timon Gehr wrote:

> It indeed seems ridiculous that you can't copy a nested struct 
> using its copy constructor. I guess one solution would be to 
> use the frame pointer of the instance you are about to copy to 
> call the copy constructor.
>
> I don't think calling it with `null` is a great idea.

Thing is you're not calling it with null. AFAIK, the compiler 
blits the context first, then calls the ctor.

Pretty much the only way to crash with nested structs is to 
either use a default-initialized value, or do some very unsafe 
things. And even then - only if you actually call methods that do 
access the context. Which not all of them have to do.

...and then we get to even more "interesting" unittests, where a 
struct contains an instance of a nested struct...


More information about the Digitalmars-d mailing list