4 ms·
It wasn't unfixed in C++17. The problem existed before C++17. This is valid code in C++11: enum class Foo : int { Invalid = 0 }; Foo f = Foo(5); In C
by Thorrez 2y ago
It wasn't unfixed in C++17. The problem existed before C++17.
This is valid code in C++11:
enum class Foo : int { Invalid = 0 };
Foo f = Foo(5);
In C++11, this compiles with Foo(5) but not Foo{5}. In C++17, this compiles with both Foo(5) and Foo{5}.
- gpderetta 2y agoIIRC for a brief period GCC considered values outside of the enumeration as UB and heavily optimized according to this. At some point this interpretetion made it as far as at least a draft standard. Then it got reverted as it went against decades of common usages and instead the opposite was made explicit in the standard. Making it UB for enum classes was considered, but the strongly typeded alias use case was considered safer and more useful.
- account42 2y agoUnfortunate. Then again, constraint value integer types are something that would be useful in general and perhaps can be provided independently of enum class.
- Sharlin 2y agoUf, I see, thanks. I could’ve sworn that this was one of the things enum class was supposed to fix.