Hacker News new | past | comments | ask | show | jobs | submit login

There is a difference between an API promissing that a value wont be null and a buggy program setting a null where it should not. A reference is only null if someone fucked up. As a programmer you can usually rely on a reference not being null and you couldn't do anything about it if it was anyway within the constraints of the language.



In the same way, an `enum class` variable's value being outside of the set defined in the `enum class` is also a fuckup.


no, deferencing a null ptr is UB. An enum class outside the declared values is perfectly valid.

You could design a language feature where integer to enum is checked, but that's not enum.

Enum classes already add scoping, forbid implicit conversions and allow explicit underlying types. Those are pure extensions. Making undeclared values invalid or UB would be very surprising to people used to normal enums.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: