Auto function without return statement, prefer an explicit void
user1234
user1234 at 12.de
Thu May 19 09:24:21 UTC 2022
On Thursday, 19 May 2022 at 09:15:50 UTC, Anonymouse wrote:
> I like explicit return types. But I also like inference.
>
> ```d
> struct SomeContainer(T)
> {
> /* ... */
> auto clear()
> {
> head = 0;
> tail = 0;
> buf[] = T.init;
> }
> }
> ```
>
> dscanner -S: `Auto function without return statement, prefer an
> explicit void`
>
> Can we please have `void clear() auto`?
The problem is when in the body you have an `asm` block that
returns.
In that case the return type cant be inferred.
```d
module runnable ;
auto notVoid()
{
asm
{
naked;
mov AL, 1;
ret;
}
}
void main()
{
auto b = notVoid();
}
```
> Error: variable `runnable.main.b` type `void` is inferred from
> initializer `notVoid()`, and variables cannot be of type `void`
but `notVoid()` actually returns a `ubyte`
More information about the Digitalmars-d
mailing list