[Issue 15100] @nogc should ignore allocations on assertion fail

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Sep 23 06:30:00 PDT 2015


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

--- Comment #3 from Steven Schveighoffer <schveiguy at yahoo.com> ---
Jonathan, I think you misunderstand.

This compiles today, and uses the gc (using a user-supplied variable to prevent
folding into assert(0)):

void main(string[] args) @nogc
{
   assert(args.length > 100, "hi");
}

But this doesn't:

assert(args.length > 100, "hi".idup);

Note that the exception isn't constructed (or allocated), and the "hi".idup
isn't run unless something fails. This code is truly @nogc unless something
goes horribly wrong, in which case the program will exit anyway, who cares if
the gc is used?

Note, I'm not advocating that the expression 'new Error("msg")' be considered
@nogc. My point in saying that is this is effectively what an assert does, and
it's considered @nogc. All I'm saying is that asserts should be treated fully
as @nogc, not just the error construction part.

--


More information about the Digitalmars-d-bugs mailing list