Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions standard/conversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -709,21 +709,22 @@ A user-defined explicit conversion from an expression `E` to a type `T` is pro
- Find the set of types, `D`, from which user-defined conversion operators will be considered. This set consists of `S₀` (if `S₀` exists and is a class or struct), the base classes of `S₀` (if `S₀` exists and is a class), `T₀` (if `T₀` is a class or struct), and the base classes of `T₀` (if `T₀` is a class). A type is added to the set `D` only if an identity conversion to another type already included in the set doesn’t exist.
- Find the set of applicable user-defined and lifted conversion operators, `U`. This set consists of the user-defined and lifted implicit or explicit conversion operators declared by the classes or structs in `D` that convert from a type encompassing `E` or encompassed by `S` (if it exists) to a type encompassing or encompassed by `T`. If `U` is empty, the conversion is undefined and a compile-time error occurs.
- Find the most-specific source type, `Sₓ`, of the operators in `U`:
- If S exists and any of the operators in `U` convert from `S`, then `Sₓ` is `S`.
- If `S` exists and any of the operators in `U` convert from `S`, then `Sₓ` is `S`.
- Otherwise, if any of the operators in `U` convert from types that encompass `E`, then `Sₓ` is the most-encompassed type in the combined set of source types of those operators. If no most-encompassed type can be found, then the conversion is ambiguous and a compile-time error occurs.
- Otherwise, `Sₓ` is the most-encompassing type in the combined set of source types of the operators in `U`. If exactly one most-encompassing type cannot be found, then the conversion is ambiguous and a compile-time error occurs.
- Find the most-specific target type, `Tₓ`, of the operators in `U`:
- If any of the operators in `U` convert to `T`, then `Tₓ` is `T`.
- Otherwise, if any of the operators in `U` convert to types that are encompassed by `T`, then `Tₓ` is the most-encompassing type in the combined set of target types of those operators. If exactly one most-encompassing type cannot be found, then the conversion is ambiguous and a compile-time error occurs.
- Otherwise, `Tₓ` is the most-encompassed type in the combined set of target types of the operators in `U`. If no most-encompassed type can be found, then the conversion is ambiguous and a compile-time error occurs.
- Find the most-specific conversion operator:
- If U contains exactly one user-defined conversion operator that converts from `Sₓ` to `Tₓ`, then this is the most-specific conversion operator.
- If `U` contains exactly one user-defined conversion operator that converts from `Sₓ` to `Tₓ`, then this is the most-specific conversion operator.
- Otherwise, if `U` contains exactly one lifted conversion operator that converts from `Sₓ` to `Tₓ`, then this is the most-specific conversion operator.
- Otherwise, the conversion is ambiguous and a compile-time error occurs.
- Finally, apply the conversion:
- If `E` does not already have the type `Sₓ`, then a standard explicit conversion from E to `Sₓ` is performed.
- The most-specific user-defined conversion operator is invoked to convert from `Sₓ` to `Tₓ`.
- If `Tₓ` is not `T`, then a standard explicit conversion from `Tₓ` to `T` is performed.
- Finally, determine the runtime conversions required, in order:
- If `E` does not already have the type `Sₓ`, then a standard explicit conversion from `E` to `Sₓ` is required.
- If this added standard explicit conversion is an explicit numeric (§10.3.2) or enumeration (§10.3.3) one which may result in information loss (§10.3.2), and the context is `unchecked` (§12.8.19), then a compile-time warning shall be issued.<br>*Note*: In a `checked` information loss would result in a runtime exception, hence no warning is required. If information loss is intended adding an explicit cast to the source will document this and silence the warning. *end note*
- The most-specific user-defined conversion operator is required to convert from `Sₓ` to `Tₓ`.
- If `Tₓ` is not `T`, then a standard explicit conversion from `Tₓ` to `T` is required.

A user-defined explicit conversion from a type `S` to a type `T` exists if a user-defined explicit conversion exists from a variable of type `S` to `T`.

Expand Down