Attribute inference for non-templated functions

Seb via Digitalmars-d digitalmars-d at puremagic.com
Wed Mar 30 05:42:42 PDT 2016


Hey while I was writing the contribution guide I stumbled over 
the issue that dmd will automatically infer attributes like @safe 
or pure in templated functions, but not in non-templated ones. 
Consider this example:

```
size_t inc(size_t a)
{
     return a + 1;
}

pure unittest
{
     assert(1.inc == 2);
}
```

It will not compile and yield and and error like "pure function 
'foo.__unittestL7_1' cannot call impure function 'foo.inc'".

Whereas the following compiles:

```
size_t incT(T = size_t)(size_t a)
{
     return a + 1;
}

pure unittest
{
     assert(1.incT == 2);
}
```

My question is whether this is just an open issue (I couldn't 
find it) or a design decision?


More information about the Digitalmars-d mailing list