@nogc and exceptions

via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 12 05:59:22 PDT 2014


On Friday, 12 September 2014 at 03:37:10 UTC, Jakob Ovrum wrote:
>   1b) Exceptions constructed at compile-time which are then 
> later referenced at runtime (as in the above snippet) must be 
> immutable (the compiler enforces this), as this feature only 
> supports allocation in global memory, not in TLS. This brings 
> us to an unsolved bug in the exception mechanism - the ability 
> to get a mutable reference to an immutable exception without 
> using a cast:

Related: Last time I checked the runtime caches unwinding or 
stack trace information in the exception. It does this even for 
immutable exceptions...

> Escaping references to caught exceptions would be undefined 
> behaviour. To statically enforce this doesn't happen, exception 
> references declared in catch-blocks could be made implicitly 
> `scope`. This depends on `scope` actually working reasonably 
> well. This would be the only breaking change for user code, and 
> the fix is simply making a copy of the escaped exception.

Care must also be taken when the exception is forwarded to 
another thread, like `receive()` does. `scope` forcing to copy 
the exception would solve a part of that, but to be completely 
correct, the exception would either have to shared, or a deep 
copy would be necessary.


More information about the Digitalmars-d mailing list