Yearly "can we please have void foo() auto" post

jmh530 john.michael.hall at gmail.com
Thu Jul 27 19:21:40 UTC 2023


On Thursday, 27 July 2023 at 18:55:25 UTC, Paul Backus wrote:
> On Thursday, 27 July 2023 at 15:22:45 UTC, Anonymouse wrote:
>> I love `auto`, it makes my life easier. The compiler infers 
>> what it can and I primarily enjoy the bonuses of `@safe` 
>> without having to annotate it manually.
>>
>> But it's not always applicable.
> [...]
>> Can we please have `void foo() auto`? It would behave as `auto 
>> foo()` does, except enforce the return type. As a bonus we'd 
>> also get `string bar() auto`.
>
> IMO the correct solution is to just make the compiler infer 
> attributes like `@safe` for *all* functions, with exceptions 
> only in cases like `extern (C)` or virtual class/interface 
> methods where the full implementation is not available, or if 
> the user explicitly opts out (e.g., with something like 
> `@noinfer`).
> [snip]

Or if the function doesn't have a body?


More information about the Digitalmars-d mailing list