-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Implicit conversions #820
Implicit conversions #820
Conversation
Co-authored-by: josh11b <[email protected]>
can for an unsigned type. We get a sign bit for free in each floating-point type, which covers all but the lowest value in iN, and the lowest value is always exactly representable because it's -2^M for a sufficiently small M.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really like this overall BTW. Also somewhat happy to defer most of the detailed review to @josh11b. =] A few minor wording / clarification comments inline, nothing super substantial though.
Co-authored-by: Chandler Carruth <[email protected]>
part of a derived-to-base pointer conversion.
Co-authored-by: josh11b <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still some useful iteration I think on lossless and semantically the same... happy to chat in person to try to reach a good solution there...
|
||
- `T` -> `U` if `T` is equivalent to `U` | ||
|
||
Two types are equivalent if they can be used interchangeably, implicitly: they |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The phrase "used interchangably" seems a bit confusing here. The subsequent explanation is clear, but maybe just jump to that?
Two types are equivalent if they can be used interchangeably, implicitly: they | |
Two types are equivalent if they |
Co-authored-by: Geoff Romer <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, ship it. I think this has converged enough, and if we get more issues that need to be clarified, I think we can fix this forward and still unblock subsequent design work.
Proposal to support a limited set of implicit conversions. This would generally permit only implicit conversions that are lossless and semantics-preserving. In particular, this proposal allows: - Conversion from an integer type to a wider integer type of the same signedness, and from an unsigned integer type to a wider signed integer type. - Conversion from an integer type to a floating-point type that has enough mantissa bits to exactly represent all integers in the source type. - Conversion from integer literals to integer and floating-point types that can represent them. - Conversion from floating-point literals to floating-point types that can represent them. - Conversions required for generics: conversions of values between facet types, and conversions of types between type-of-types, as described in the generics proposals. - Conversions required for inheritance: derived-to-base conversions for class pointers and class values. Other conversions, such as lossy conversions between arithmetic types and conversions between bool and other types are not supported. Co-authored-by: josh11b <[email protected]> Co-authored-by: Chandler Carruth <[email protected]> Co-authored-by: Geoff Romer <[email protected]>
Proposal to support a limited set of implicit conversions. This would generally permit only implicit conversions that are lossless and semantics-preserving. In particular, this proposal allows:
Other conversions, such as lossy conversions between arithmetic types and conversions between
bool
and other types are not supported.A mechanism to permit user-defined types to support implicit conversion is provided: