Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[expr.static.cast] p10 Circular definition of explicitly converting an integer value to enumeration type #5392

Open
xmh0511 opened this issue Apr 14, 2022 · 0 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Apr 14, 2022

[expr.static.cast] p10 says

A value of integral or enumeration type can be explicitly converted to a complete enumeration type. If the enumeration type has a fixed underlying type, the value is first converted to that type by integral promotion ([conv.prom]) or integral conversion ([conv.integral]), if necessary, and then to the enumeration type.

Consider this example

enum class Destination: int{};
char c = 0;
auto t = (Destination)c;

The enumeration type Destination has a fixed type that is int, while the source is of type char. According to the above rule, the prvalue of type char is firstly converted to int with an integral promotion, we get a middle prvalue of type int, then convert it to the enumeration type Destination. How does a prvalue of integer type(i.e. int) convert to the enumeration type Destination? There is no standard conversion that specifies such an effect:

Destination v = 0;

The same issue is also in

A value of floating-point type can also be explicitly converted to an enumeration type. The resulting value is the same as converting the original value to the underlying type of the enumeration ([conv.fpint]), and subsequently to the enumeration type.

we do not specify how to convert a value of the underlying type of the enumeration E to type E, or to say that such a conversion would circularly depend on [expr.static.cast] p10. We even do not know whether convert to means explicitly convert to or implicitly convert to for converting the middle result to the final.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant