Local functions infer attributes?

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Sat Sep 27 19:56:55 PDT 2014


On Sunday, 28 September 2014 at 02:42:29 UTC, Manu via 
Digitalmars-d wrote:
> void f() pure nothrow @nogc
> {
>    void localFunc()
>    {
>    }
>
>    localFunc();
> }
>
> Complains because localFunc is not @nogc or nothrow.
> Doesn't complain about pure though.
>
> Is it reasonable to say that the scope of the outer function is
> nothrow+ at nogc, and therefore everything declared within should 
> also be
> so?

No as the function could be returned and used elsewhere, where 
these attribute aren't necessary. Also, inferring everything is 
quite expensive and we want D to compile fast.

But maybe inference could be triggered on error ?


More information about the Digitalmars-d mailing list