Why aren't function attributes inferred?
Timon Gehr
timon.gehr at gmx.ch
Sat Aug 20 10:16:14 PDT 2011
On 08/20/2011 06:50 PM, Sean Eskapp wrote:
> Since the compiler can clearly tell when a function is not const, safe, pure,
> or nothrow, why can't they just be assumed, unless proven otherwise?
This sort of inference is already done for function/delegate literals
and template functions.
It is not done for other functions, because eg. their code is not
necessarily available.
int foo(int x) pure; // how would you infer purity here?
Also, if normal functions would infer those attributes, they would be
leaking implementation details all over the place. If a pure
implementation would have to be changed to a non-pure one, all code that
relied on the undocumented but inferred purity would break.
More information about the Digitalmars-d-learn
mailing list