A valid function with no return type?
Max Haughton
maxhaton at gmail.com
Thu Sep 24 21:42:53 UTC 2020
On Thursday, 24 September 2020 at 21:31:27 UTC, Adam D. Ruppe
wrote:
> On Thursday, 24 September 2020 at 21:26:30 UTC, Max Haughton
> wrote:
>> Assuming this is supposed to be allowed by the standard,
>
> Yes, this is expected.
>
> So the `auto` keyword in D is actually a do-nothing
> placeholder. It just indicates to the grammar that a
> declaration is coming. Any other keyword that is only valid in
> declarations does the same job and then implies `auto`.
>
> In local variables it is often common to see like
>
> const a = 5;
>
> And in function declarations, a variety of things triggers the
> same thing including pure, ref, @safe, or even user-defined
> attributes. Just enough to tell the compiler a function is
> coming, then it assumes `auto` return until it sees a concrete
> type instead.
>
>> replacing void with ref (i.e. ref main { ) does not compile
>> which suggests something isn't right.
>
> main is special, it must have a specific signature to be
> registered.
Main will still compile if you indirect the return type through a
template i.e. YourFavouriteMixin!"int" main(), whereas it doesn't
get inferred at all for ref main (ref int main() {} gets through
to regular sema)
Even if this behaviour is OK in the standard it still gives me
the heebie-jeebies.
More information about the Digitalmars-d
mailing list