Debug prints in @nogc
Yuxuan Shui via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Aug 31 16:07:10 PDT 2016
On Wednesday, 31 August 2016 at 19:39:36 UTC, ag0aep6g wrote:
> On 08/31/2016 09:23 PM, Yuxuan Shui wrote:
>> Correct me if I'm wrong. But I believe this is only true when
>> the source
>> code of function is not available. Otherwise the compiler
>> should always
>> know if a function is actually @nogc or not.
>
> Attributes are only inferred in certain cases where the source
> code must be available anyway (templates, `auto` return value).
> For ordinary functions, the compiler only considers them @nogc
> when they're explicitly marked.
>
> For example, the compiler won't let you do this, even though
> f's source code is available and it's obviously de-facto @nogc:
>
> ----
> void f() {}
> void main() @nogc { f(); }
> ----
That's a good point. By IMHO, all the (non-template) function in
Phobos that can be marked @nogc, should be marked @nogc,
otherwise it's a bug. If the function is in your own code, you
should use @nogc, not assumeNogc.
After a second thought, the real use case of assumeNogc is
probably virtual functions. But then again, it is kind of
dangerous to use it even in this case.
More information about the Digitalmars-d-learn
mailing list