Local functions infer attributes?
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Sun Sep 28 05:21:10 PDT 2014
On 9/27/14, 7:42 PM, 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?
Interesting. I'd guess probably not, e.g. a function may define a static
local function and return its address (without either throwing or
creating garbage), whereas that local function itself may do whatever it
pleases.
However, local functions have their body available by definition so they
should have all deducible attributes deducted. That should take care of
the problem.
Andrei
P.S. I also notice that my latest attempt at establishing communication
has remained ignored.
More information about the Digitalmars-d
mailing list