enum functions

Steven Schveighoffer schveiguy at gmail.com
Wed Jan 11 15:17:42 UTC 2023


On 1/10/23 7:55 AM, Adam D Ruppe wrote:
> On Sunday, 8 January 2023 at 18:42:58 UTC, Salih Dincer wrote:
>> I'm wondering 2 things; firstly, does having an enum mean there is no 
>> auto-return? Or could it be CTFE?
> 
> It means nothing. The keyword tells the parser a function is about to 
> begin, which triggers return type inference (exactly the same as 
> `auto`), but otherwise it is completely ignored.

Mostly correct. `enum` is a storage class, which means a *declaration* 
is about to begin. Once the declaration is decided as a function 
definition, type inference is performed, and the storage class is 
checked to see how it affects the declaration. In some cases, there is 
an effect, in some there is not.

```d
static foo() {} // static does nothing here
final bar() {} // final does nothing here
enum baz() {} // enum does nothing here
__gshared fun() {} // __gshared does nothing here

struct S
{
    // return type is int *, `this` (unused) is const
    const foo() { return new int; }
    // same for immutable, shared, inout
}
```

Aside from the const/immutable/shared/inout storage classes (which do 
affect semantics, but maybe in slightly confusing ways) there are some 
which are pretty obvious and also work with type inference:

1. deprecated
2. extern
3. abstract
4. override
5. synchronized
6. auto
7. scope
8. nothrow
9. pure
10. ref

-Steve


More information about the Digitalmars-d-learn mailing list