[Issue 3572] declaring pure function with void return type should be compile time error

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 24 11:10:21 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=3572

Dennis <dkorpel at live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
                 CC|                            |dkorpel at live.nl
         Resolution|---                         |INVALID

--- Comment #9 from Dennis <dkorpel at live.nl> ---
(In reply to yebblies from comment #8)
> eg.
> pure void foo(string x)
> By definition calling foo does no observable work.

False.

```
pure void foo(string x) {
    throw new Exception(x);
}
```

Here's a nothrow one:
```
pure nothrow void assertPositive(int x) {
    assert(x > 0);
}
```

> While this might be WONTFIX or LATER like issue 3882, it is not invalid.

Until a case can be identified where there is actually "no observable work"
guaranteed, this is invalid.

(And even then, it's debatable whether "no observable work" is enough grounds
to make something not compile. `int x = 0; x += 0;` does nothing, but it does
and should compile.)

--


More information about the Digitalmars-d-bugs mailing list