cplusplus / cplusplus/draft

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

Open
#5,392 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TeX
Stars
221
Forks
813
Avg merge
16h 4m
Merged PRs (30d)
36

Description

[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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read [expr.static.cast] p10 alongside [conv.prom], [conv.integral], and [conv.fpint], then trace both the integral and floating-point examples in the issue. Determine wording that defines conversion to the enumeration type without circularity or ambiguity about explicit versus implicit conversion; done means both cases are specified coherently in the draft.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, tex
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.