What is the current state of scope and member functions?

Dennis dkorpel at gmail.com
Tue Sep 12 10:48:13 UTC 2023


On Tuesday, 12 September 2023 at 09:52:58 UTC, Jonathan M Davis 
wrote:
> and my gut reaction is that it would be better to just slap 
> @trusted in a bunch of places to shut the compiler up about 
> scope than it would be to try to actually make it work - though 
> unfortunately, that's not going to work very well with 
> templated code (particularly in libraries), which is precisely 
> where I'm seeing the compiler complain about scope even though 
> I'm not doing stuff like taking the address of local variables.

Please file a bug when you get lifetime errors while not taking 
the address of a local. Note that slicing a local static array is 
taking the address, and it being allowed in @safe code without 
dip1000 is a long standing accepts-invalid bug. dip1000 is 
strictly allowing more code to compile, and all the breakage 
comes from the accepts-invalid bug. Robert's DConf '23 proposal 
to simplify by disallowing @safe code slicing local static arrays 
altogether  strictly breaks more code.

As for removing the scope-stripping of member functions, I 
remember I tried that, but failed because it would break code in 
an unexpected way (forward references again):

https://github.com/dlang/dmd/pull/14232#issuecomment-1162906573



More information about the Digitalmars-d mailing list