Recursion and attribute inference

Dukc ajieskola at gmail.com
Wed Nov 2 19:17:10 UTC 2022


While writing about attribute inference to a D blog post draft, I 
encountered an ambiguous case.

```D
float recurse()(float val, float till)
{
     return val < till? recurse(val * 2, till): val;
}

@safe void main()
{
     import std;

     writeln(recurse(1.5, 40.0));
     writeln(typeid(&recurse!()));
}
```

This compiles and prints

```
48
float function(float, float) pure nothrow @nogc @safe*
```

. However, the [spec 
says](https://dlang.org/spec/function.html#function-attribute-inference) that a function that recurses will not be inferred as `@safe`, `pure` or `nothrow`.

Which is right here, the implementation or the spec?


More information about the Digitalmars-d mailing list