On heap segregation, GC optimization and @nogc relaxing

via Digitalmars-d digitalmars-d at puremagic.com
Fri Nov 14 12:22:12 PST 2014


On Friday, 14 November 2014 at 19:02:52 UTC, Dmitry Olshansky 
wrote:
> Here is the case I wanted to check:
>
> try{
> 	...
> }
> catch(owned(Exception) e){
> 	foo(e);
> }
>
> void foo(T)(T arg){
> 	// what would this print? Exception or owned(Exception)
> 	// do we bloat a bit more on qualifiers?
> 	pragma(msg, T);
> }

It needs to be `owned(Exception)`, otherwise, how could the 
compiler know how to treat it correctly? But declaring foo() in 
that way would be unhelpful, because it would move the exception 
on calling the function, which is usually not desired. What you 
want here, instead, is borrowing:

     void foo(T)(scope(T) arg) {
         pragma(msg, T);
     }


More information about the Digitalmars-d mailing list