Bug 15916 – void makes a function impure + system

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-04-12T18:09:00Z
Last change time
2016-04-12T18:15:39Z
Assigned to
nobody
Creator
greeenify

Comments

Comment #0 by greeenify — 2016-04-12T18:09:09Z
auto myfun(int foo) { auto b = foo; } pure @safe nothrow unittest { myfun(2); } However once the return type is void - the compiler tells me that I have an impure system function! Is this by design or a bug? void myfunv() { int b = 2; } pure @safe nothrow unittest { myfunv(); } (removing/adding the parameter doesn't make a difference)
Comment #1 by mathias.lang — 2016-04-12T18:15:39Z
It is by design. The compiler will perform attribute inference on `auto` returning functions and templates, but not on function where the full prototype is provided. Attribute inference for regular function would make it impossible to provide the prototype of a function in a sane way (as you can provide `.di` files which are D equivalent of headers). Closing as invalid, feel free to head to the 'learn' forum if you have any more question.