A potential issue in Construction Rules for enum class Values (P0138R2)

24 views
Skip to first unread message

Andrey Upadyshev

unread,
Jun 7, 2018, 6:15:03 PM6/7/18
to ISO C++ Standard - Discussion
Hi,

In the Construction Rules for enum class Values (p0138r2) I see contradictory expressions about allowing relaxed initialization for enum types with
declared enumerators:

a) The text says:
EWG did consider the request of extending the relaxation suggested in this paper to enumerations 
with declared enumerators, but ultimately rejected that suggestion.
 Which I understand as that the new relaxed initialization should be only applied to enums without enumerators.

b) But the example shows the opposite:
enum class Handle : uint32_t { Invalid = 0 };
Handle h { 42 };  // OK

Does anybody know whether it was decided to apply the new relaxed initialization to enums without enumerators or not?
And if yes then what was the logic behind this decision? (I can't come up with any good argument for allowing such an easy way to violate an enum's domain.)

Thank you,
Andrey

P.S. That's my first topic in the group so please be indulgent and point me to the group rules I have to follow.

Nathan Ernst

unread,
Jun 7, 2018, 6:26:16 PM6/7/18
to std-dis...@isocpp.org
I don't have the standardese in front of me, but it looks like to me that in b), you're explicitly initializing from an int, which is allowed by the standard. I think only implicit constructions are disallowed in the face of "enum class".

Regards,
Nate

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.

Andrey Upadyshev

unread,
Jun 7, 2018, 7:10:14 PM6/7/18
to ISO C++ Standard - Discussion
Do you mean it is allowed in C++17? Because in C++14 such initialization is not allowed for scoped enums. One had to use static cast as following:
enum class Handle : uint32_t { Invalid = 0 };
Handle h{42};                       // error
Handle h{static_cast<Handle>(42)};  // OK

Reply all
Reply to author
Forward
0 new messages