What is that "enum function" supposed to be ?

bauss jj_1337 at live.dk
Tue Jul 20 10:09:32 UTC 2021


On Tuesday, 20 July 2021 at 09:15:42 UTC, Patrick Schluter wrote:
> 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.

You can also do confusing things like this:

```d
@safe x = 12;
```

D is almost like "just give me whatever, if I can use it then 
I'll use it, if I can't then I'll skip it.


More information about the Digitalmars-d mailing list