Thread overview | ||||||
---|---|---|---|---|---|---|
|
April 02, 2019 Forbidding implicit conversions from an enum type to an integer | ||||
---|---|---|---|---|
| ||||
Is there a way (compiler flag) to forbid implicit conversions from an enum type to integer types? |
April 02, 2019 Re: Forbidding implicit conversions from an enum type to an integer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Per Nordlöw | On Tuesday, 2 April 2019 at 08:38:28 UTC, Per Nordlöw wrote:
> Is there a way (compiler flag) to forbid implicit conversions from an enum type to integer types?
You can make the enum type not an integer type.
```
struct Int{int i;}
enum E: Int {
first = Int(0),
second = Int(1),
}
```
|
April 02, 2019 Re: Forbidding implicit conversions from an enum type to an integer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis | On Tuesday, 2 April 2019 at 09:02:03 UTC, Dennis wrote:
> You can make the enum type not an integer type.
>
> ```
> struct Int{int i;}
>
> enum E: Int {
> first = Int(0),
> second = Int(1),
> }
> ```
Thanks.
Are there any plans on deprecating implicit conversions of enums to integers?
|
April 02, 2019 Re: Forbidding implicit conversions from an enum type to an integer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Per Nordlöw | On Tuesday, 2 April 2019 at 09:37:26 UTC, Per Nordlöw wrote: > Are there any plans on deprecating implicit conversions of enums to integers? Not that I know of. Given the precedence of this: https://github.com/dlang/DIPs/blob/master/DIPs/rejected/DIP1015.md I doubt enum/integer-types are going to get stricter. Is there a particular bug you encountered because of this conversion? |
Copyright © 1999-2021 by the D Language Foundation