Auto attributes for functions

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 20 02:12:44 PDT 2014


On Wed, 20 Aug 2014 01:38:52 +0000
uri via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com> wrote:

> Hi all,
>
> Bit new to D so this might be a very naive question...
>
> Can the compiler auto infer function attributes?
>
> I am often adding as many attributes as possible and use the
> compiler to show me where they're not applicable and take them
> away. It would be great if this could be achieved like so:
>
> auto function() @auto
> {}
>
> instead of manually writing:
>
> auto function() pure @safe nothrow @nogc const
> {}

Currently, just templated functions get their attributes inferred. The biggest
problem with inferring them for all functions is that you can declare a
function without defining it in the same place (e.g. if you're using .di
files), in which case the compiler has no function body to use for attribute
inferrence.

There have been discussions on ways to reasonably infer attributes under more
circumstances, but nothing has come of them yet. However, I'd expect that
there will be at least some improvements to the situation at some point given
that there is a general consensus that while the attributes are quite useful,
it's also rather annoying to have to keep typing them all.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list