[Issue 13972] Make scoped, Unique, and RefCounted @nogc

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Jan 12 20:32:50 PST 2015


https://issues.dlang.org/show_bug.cgi?id=13972

Kapps <opantm2+dbugs at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |opantm2+dbugs at gmail.com

--- Comment #1 from Kapps <opantm2+dbugs at gmail.com> ---
I've looked at making some obvious things @nogc (RefCounted,
std.container.array, etc), but have always been blocked by the use of
exceptions. There was some talk about how to handle @nogc exceptions, but no
real conclusion came of it. Virtually all of these structs that are supposed to
completely avoid the GC do not actually do so because they allocate exceptions
with the GC (whether by enforce or manually throwing). This is also one of the
main reasons I never use @nogc in my own code, even though I avoid using the
GC. In some cases there's an obvious solution, such as replacing `enforce(foo)`
with:

````
if(foo is null) {
    static ex = cast(immutable)(new Exception("foo is null"));
    throw ex;
}
````

But that's considerably uglier and does not help in situations where the
exception text includes additional information from runtime arguments. Also I'm
not sure what kind of impact this would have if called and thrown in a catch
block. 

It would be nice to confirm what approach for avoiding GC exceptions should be
used in Phobos, as AFAIK nothing was ever decided, and I'm not sure of an
approach without drawbacks towards those who do use the GC.

--


More information about the Digitalmars-d-bugs mailing list