On attribute inference...

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Tue Apr 19 15:08:13 PDT 2016


On 4/18/2016 8:20 PM, Jonathan M Davis via Digitalmars-d wrote:
> Except that unfortunately, the compiler _does_ do attribute inference for
> auto return functions now, because the body is guaranteed to be available.
> Relying on that inference in a public API that's part of a library will
> easily lead to code breakage when the function implementation is changed (or
> even when a function that it calls is changed, if that affects its
> attributes).
>
> Personally, I think that adding attribute inference for auto return
> functions was a mistake and just encourages bad practices, but unless Walter
> can be convinced that it was such a bad idea that it needs to be reverted
> (and break whatever code thatt that would break), we're stuck with it.
> Regardless, I think that it's clear that if you want a stable API, you need
> to infer attributes as little as possible.

Auto function attribute inference is a good idea. They really aren't 
conceptually different from templates. Note that the mangling of an auto 
function will change if its attributes change, thus meaning you should get a 
link failure.

Attribute inference is a huge win for D, it makes the mass of attributes manageable.



More information about the Digitalmars-d mailing list