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

Paul Backus snarwin at gmail.com
Thu Jul 27 19:56:27 UTC 2023


On Thursday, 27 July 2023 at 19:34:09 UTC, H. S. Teoh wrote:
> On Thu, Jul 27, 2023 at 06:55:25PM +0000, Paul Backus via 
> Digitalmars-d wrote: [...]
>> 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`).
>
> Opting out could be as simple as specifying at least one 
> attribute explicitly.  Where no attributes are specified, it 
> should be inferred by default.

Problematic when it comes to code like the following:

     nothrow @nogc:

     void foo()
     {
         // ...
     }

     auto bar()
     {
         // ...
     }

For `bar`, the compiler will currently infer @safe and pure, even 
though nothrow and @nogc have been specified explicitly. For 
consistency, if we want to extend attribute inference to `foo`, 
it needs to work the same way.



More information about the Digitalmars-d mailing list