What is that "enum function" supposed to be ?

Patrick Schluter Patrick.Schluter at bbox.fr
Tue Jul 20 09:15:42 UTC 2021


On Monday, 19 July 2021 at 21:31:40 UTC, Paul Backus wrote:
> On Monday, 19 July 2021 at 21:16:57 UTC, Elmar wrote:
>> I'd like to know:
>> - What does return type `enum` mean?
>
> It just means `auto`. Probably it shouldn't be allowed at all, 
> but D's parser is sometimes overly-permissive and will accept 
> things like this even when they don't really make sense.
>

The issue is that people misunderstand `auto` and type inference. 
It's a variable definition with initializer and a storage class 
WITHOUT a type.

The grammar is clear though

     ```
     AutoDeclaration:
         StorageClasses AutoAssignments ;

     StorageClasses:
         StorageClass
         StorageClass StorageClasses

     StorageClass:
         LinkageAttribute
         AlignAttribute
         AtAttribute
         deprecated
         enum
         static
         extern
         abstract
         final
         override
         synchronized
         auto
         scope
         const
         immutable
         inout
         shared
         __gshared
         Property
         nothrow
         pure
         ref
     ```


> For example, you can also declare a `@nogc` variable:
>
> ```d
> @nogc x = new Object;
> ```
>

deprecated x = new Object;

@dummy y = 1;

> The `@nogc` attribute doesn't do anything here, but the 
> compiler allows it anyway.




More information about the Digitalmars-d mailing list