<div dir="ltr"><div>Thanks, this was helpful!<br><br></div>LMB<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Aug 23, 2014 at 1:22 PM, monarch_dodra via Digitalmars-d-learn <span dir="ltr"><<a href="mailto:digitalmars-d-learn@puremagic.com" target="_blank">digitalmars-d-learn@puremagic.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Saturday, 23 August 2014 at 15:26:02 UTC, Leandro Motta Barros via Digitalmars-d-learn wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
I have a module which is completelly @nogc, and as such I'd like to just say<br>
<br>
   @nogc:<br>
<br>
at the top of the file and be happy.<br>
<br>
However, my unit tests for this same module do some GC allocation, so the<br>
module fails to compile.<br>
<br>
Is there a way to disable @nogc for the unit tests only? Would this be a<br>
bad idea in some way I cannot see?<br>
</blockquote>
<br></div>
Nope. At best, you might be able to *declare* a function that is GC, but even then, you wouldn't be able to call it.<div class=""><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I suppose the same question is valid for other attributes, like 'nothrow'<br>
and '@safe'.<br>
</blockquote>
<br></div>
Actually, you can "undo" @safe with an explicit @system. nothrow (and pure) are in the same boat as @nogc<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thank you,<br>
<br>
LMB<br>
</blockquote>
<br>
Solutions I can see would be to:<br>
a) Put your unittests in a separate module.<br>
b) Place your unittests before your "@nogc:"<br>
c) Instead of using "@nogc:", use "@nogc {}": This will make @nogc run until the end of the block.<br>
</blockquote></div><br></div>