On Friday, May 11, 2018 10:05:12 Shachar Shemesh via Digitalmars-d wrote: > At least under Linux, you cannot get or set the value of errno from a > nothrow function. > > Is this on purpose, or is this a bug?
In general, the C bindings in druntime haven't ended up with much in the way of attributes on them - in part, because many of the predate a lot of the attributes, and in part, because it can take some time and effort to figure out what the correct attributes are, so they frequently don't get put on like they should be. In the case of errno, it's coming from core.stdc.errno, and it looks like on pretty much every system, it's declared as an alias for an extern(C) function - e.g. ref int __error(); and none of them are marked with any attributes. In this particular case, I would think that they could be marked with @trusted, nothrow, and @nogc. I don't know about pure. Probably not, but I could see it being a treated a bit like floating point flags where pure functions are allowed to muck with them even though they're arguably global state. So, I don't know. In any case, it's an easy fix, so I created a quick PR to fix it: https://github.com/dlang/druntime/pull/2180 - Jonathan M Davis