tmp/tmp7916_luy/{from.md → to.md}
RENAMED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
## Standard conversions <a id="conv">[[conv]]</a>
|
| 2 |
|
|
|
|
|
|
|
| 3 |
Standard conversions are implicit conversions with built-in meaning.
|
| 4 |
[[conv]] enumerates the full set of such conversions. A *standard
|
| 5 |
conversion sequence* is a sequence of standard conversions in the
|
| 6 |
following order:
|
| 7 |
|
|
@@ -80,14 +82,16 @@ the operand of the unary `&` operator. Specific exceptions are given in
|
|
| 80 |
the descriptions of those operators and contexts. — *end note*]
|
| 81 |
|
| 82 |
### Lvalue-to-rvalue conversion <a id="conv.lval">[[conv.lval]]</a>
|
| 83 |
|
| 84 |
A glvalue [[basic.lval]] of a non-function, non-array type `T` can be
|
| 85 |
-
converted to a prvalue.[^5]
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
|
| 90 |
When an lvalue-to-rvalue conversion is applied to an expression E, and
|
| 91 |
either
|
| 92 |
|
| 93 |
- E is not potentially evaluated, or
|
|
@@ -122,13 +126,12 @@ rules:
|
|
| 122 |
`T` is volatile-qualified [[intro.execution]], and the glvalue can
|
| 123 |
refer to an inactive member of a union [[class.union]]. — *end note*]
|
| 124 |
- Otherwise, if `T` has a class type, the conversion copy-initializes
|
| 125 |
the result object from the glvalue.
|
| 126 |
- Otherwise, if the object to which the glvalue refers contains an
|
| 127 |
-
invalid pointer value
|
| 128 |
-
|
| 129 |
-
*implementation-defined*.
|
| 130 |
- Otherwise, the object indicated by the glvalue is read
|
| 131 |
[[defns.access]], and the value contained in the object is the prvalue
|
| 132 |
result.
|
| 133 |
|
| 134 |
[*Note 2*: See also [[basic.lval]]. — *end note*]
|
|
@@ -166,46 +169,46 @@ int k = X().n; // OK, X() prvalue is converted to xvalue
|
|
| 166 |
|
| 167 |
— *end example*]
|
| 168 |
|
| 169 |
### Qualification conversions <a id="conv.qual">[[conv.qual]]</a>
|
| 170 |
|
| 171 |
-
A *
|
| 172 |
-
`T` is
|
| 173 |
|
| 174 |
where each cvᵢ is a set of cv-qualifiers [[basic.type.qualifier]], and
|
| 175 |
each Pᵢ is “pointer to” [[dcl.ptr]], “pointer to member of class Cᵢ of
|
| 176 |
type” [[dcl.mptr]], “array of Nᵢ”, or “array of unknown bound of”
|
| 177 |
[[dcl.array]]. If Pᵢ designates an array, the cv-qualifiers cvᵢ₊₁ on the
|
| 178 |
element type are also taken as the cv-qualifiers cvᵢ of the array.
|
| 179 |
|
| 180 |
[*Example 1*: The type denoted by the *type-id* `const int **` has
|
| 181 |
-
three
|
| 182 |
-
`const int`”, and as “pointer to pointer to
|
| 183 |
`const int`”. — *end example*]
|
| 184 |
|
| 185 |
The n-tuple of cv-qualifiers after the first one in the longest
|
| 186 |
-
|
| 187 |
-
*cv-qualification signature* of `T`.
|
| 188 |
|
| 189 |
-
Two types `T1` and `T2` are *similar* if they have
|
| 190 |
-
with the same n such that corresponding Pᵢ
|
| 191 |
-
same or one is “array of Nᵢ” and the other is
|
| 192 |
-
of”, and the types denoted by `U` are the same.
|
| 193 |
|
| 194 |
-
The *
|
| 195 |
-
similar to `T1` whose
|
| 196 |
|
| 197 |
-
- for every i > 0, cv³ᵢ is the union of cv¹ᵢ and cv²ᵢ
|
| 198 |
- if either P¹ᵢ or P²ᵢ is “array of unknown bound of”, P³ᵢ is “array of
|
| 199 |
-
unknown bound of”, otherwise it is P¹ᵢ
|
| 200 |
- if the resulting cv³ᵢ is different from cv¹ᵢ or cv²ᵢ, or the resulting
|
| 201 |
P³ᵢ is different from P¹ᵢ or P²ᵢ, then `const` is added to every cv³ₖ
|
| 202 |
-
for 0 < k < i
|
| 203 |
|
| 204 |
-
where cvʲᵢ and Pʲᵢ are the components of the
|
| 205 |
-
prvalue of type `T1` can be converted to type `T2` if the
|
| 206 |
-
type of `T1` and `T2` is `T2`.
|
| 207 |
|
| 208 |
[*Note 1*:
|
| 209 |
|
| 210 |
If a program could assign a pointer of type `T**` to a pointer of type
|
| 211 |
`const` `T**` (that is, if line \#1 below were allowed), a program could
|
|
@@ -223,12 +226,12 @@ int main() {
|
|
| 223 |
```
|
| 224 |
|
| 225 |
— *end note*]
|
| 226 |
|
| 227 |
[*Note 2*: Given similar types `T1` and `T2`, this construction ensures
|
| 228 |
-
that both can be converted to the
|
| 229 |
-
`T2`. — *end note*]
|
| 230 |
|
| 231 |
[*Note 3*: A prvalue of type “pointer to *cv1* `T`” can be converted to
|
| 232 |
a prvalue of type “pointer to *cv2* `T`” if “*cv2* `T`” is more
|
| 233 |
cv-qualified than “*cv1* `T`”. A prvalue of type “pointer to member of
|
| 234 |
`X` of type *cv1* `T`” can be converted to a prvalue of type “pointer to
|
|
@@ -239,24 +242,24 @@ than “*cv1* `T`”. — *end note*]
|
|
| 239 |
pointer-to-member-function types) are never cv-qualified
|
| 240 |
[[dcl.fct]]. — *end note*]
|
| 241 |
|
| 242 |
### Integral promotions <a id="conv.prom">[[conv.prom]]</a>
|
| 243 |
|
| 244 |
-
A prvalue of an integer type other than `bool`, `
|
| 245 |
-
or `wchar_t` whose integer conversion rank [[conv.rank]] is
|
| 246 |
-
the rank of `int` can be converted to a prvalue of type `int`
|
| 247 |
-
can represent all the values of the source type; otherwise, the
|
| 248 |
-
prvalue can be converted to a prvalue of type `unsigned int`.
|
| 249 |
|
| 250 |
-
A prvalue of type `char16_t`, `char32_t`, or `wchar_t`
|
| 251 |
[[basic.fundamental]] can be converted to a prvalue of the first of the
|
| 252 |
following types that can represent all the values of its underlying
|
| 253 |
type: `int`, `unsigned int`, `long int`, `unsigned long int`,
|
| 254 |
`long long int`, or `unsigned long long int`. If none of the types in
|
| 255 |
that list can represent all the values of its underlying type, a prvalue
|
| 256 |
-
of type `char16_t`, `char32_t`, or `wchar_t` can be converted
|
| 257 |
-
prvalue of its underlying type.
|
| 258 |
|
| 259 |
A prvalue of an unscoped enumeration type whose underlying type is not
|
| 260 |
fixed can be converted to a prvalue of the first of the following types
|
| 261 |
that can represent all the values of the enumeration [[dcl.enum]]:
|
| 262 |
`int`, `unsigned int`, `long int`, `unsigned long int`, `long long int`,
|
|
@@ -277,12 +280,12 @@ can also be converted to a prvalue of the promoted underlying type.
|
|
| 277 |
A prvalue for an integral bit-field [[class.bit]] can be converted to a
|
| 278 |
prvalue of type `int` if `int` can represent all the values of the
|
| 279 |
bit-field; otherwise, it can be converted to `unsigned int` if
|
| 280 |
`unsigned int` can represent all the values of the bit-field. If the
|
| 281 |
bit-field is larger yet, no integral promotion applies to it. If the
|
| 282 |
-
bit-field has
|
| 283 |
-
|
| 284 |
|
| 285 |
A prvalue of type `bool` can be converted to a prvalue of type `int`,
|
| 286 |
with `false` becoming zero and `true` becoming one.
|
| 287 |
|
| 288 |
These conversions are called *integral promotions*.
|
|
@@ -312,16 +315,19 @@ The conversions allowed as integral promotions are excluded from the set
|
|
| 312 |
of integral conversions.
|
| 313 |
|
| 314 |
### Floating-point conversions <a id="conv.double">[[conv.double]]</a>
|
| 315 |
|
| 316 |
A prvalue of floating-point type can be converted to a prvalue of
|
| 317 |
-
another floating-point type
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
the
|
|
|
|
|
|
|
|
|
|
| 323 |
|
| 324 |
The conversions allowed as floating-point promotions are excluded from
|
| 325 |
the set of floating-point conversions.
|
| 326 |
|
| 327 |
### Floating-integral conversions <a id="conv.fpint">[[conv.fpint]]</a>
|
|
|
|
| 1 |
## Standard conversions <a id="conv">[[conv]]</a>
|
| 2 |
|
| 3 |
+
### General <a id="conv.general">[[conv.general]]</a>
|
| 4 |
+
|
| 5 |
Standard conversions are implicit conversions with built-in meaning.
|
| 6 |
[[conv]] enumerates the full set of such conversions. A *standard
|
| 7 |
conversion sequence* is a sequence of standard conversions in the
|
| 8 |
following order:
|
| 9 |
|
|
|
|
| 82 |
the descriptions of those operators and contexts. — *end note*]
|
| 83 |
|
| 84 |
### Lvalue-to-rvalue conversion <a id="conv.lval">[[conv.lval]]</a>
|
| 85 |
|
| 86 |
A glvalue [[basic.lval]] of a non-function, non-array type `T` can be
|
| 87 |
+
converted to a prvalue.[^5]
|
| 88 |
+
|
| 89 |
+
If `T` is an incomplete type, a program that necessitates this
|
| 90 |
+
conversion is ill-formed. If `T` is a non-class type, the type of the
|
| 91 |
+
prvalue is the cv-unqualified version of `T`. Otherwise, the type of the
|
| 92 |
+
prvalue is `T`.[^6]
|
| 93 |
|
| 94 |
When an lvalue-to-rvalue conversion is applied to an expression E, and
|
| 95 |
either
|
| 96 |
|
| 97 |
- E is not potentially evaluated, or
|
|
|
|
| 126 |
`T` is volatile-qualified [[intro.execution]], and the glvalue can
|
| 127 |
refer to an inactive member of a union [[class.union]]. — *end note*]
|
| 128 |
- Otherwise, if `T` has a class type, the conversion copy-initializes
|
| 129 |
the result object from the glvalue.
|
| 130 |
- Otherwise, if the object to which the glvalue refers contains an
|
| 131 |
+
invalid pointer value [[basic.stc.dynamic.deallocation]], the behavior
|
| 132 |
+
is *implementation-defined*.
|
|
|
|
| 133 |
- Otherwise, the object indicated by the glvalue is read
|
| 134 |
[[defns.access]], and the value contained in the object is the prvalue
|
| 135 |
result.
|
| 136 |
|
| 137 |
[*Note 2*: See also [[basic.lval]]. — *end note*]
|
|
|
|
| 169 |
|
| 170 |
— *end example*]
|
| 171 |
|
| 172 |
### Qualification conversions <a id="conv.qual">[[conv.qual]]</a>
|
| 173 |
|
| 174 |
+
A *qualification-decomposition* of a type `T` is a sequence of cvᵢ and
|
| 175 |
+
Pᵢ such that `T` is
|
| 176 |
|
| 177 |
where each cvᵢ is a set of cv-qualifiers [[basic.type.qualifier]], and
|
| 178 |
each Pᵢ is “pointer to” [[dcl.ptr]], “pointer to member of class Cᵢ of
|
| 179 |
type” [[dcl.mptr]], “array of Nᵢ”, or “array of unknown bound of”
|
| 180 |
[[dcl.array]]. If Pᵢ designates an array, the cv-qualifiers cvᵢ₊₁ on the
|
| 181 |
element type are also taken as the cv-qualifiers cvᵢ of the array.
|
| 182 |
|
| 183 |
[*Example 1*: The type denoted by the *type-id* `const int **` has
|
| 184 |
+
three qualification-decompositions, taking `U` as “`int`”, as “pointer
|
| 185 |
+
to `const int`”, and as “pointer to pointer to
|
| 186 |
`const int`”. — *end example*]
|
| 187 |
|
| 188 |
The n-tuple of cv-qualifiers after the first one in the longest
|
| 189 |
+
qualification-decomposition of `T`, that is, cv₁, cv₂, …, cvₙ, is called
|
| 190 |
+
the *cv-qualification signature* of `T`.
|
| 191 |
|
| 192 |
+
Two types `T1` and `T2` are *similar* if they have
|
| 193 |
+
qualification-decompositions with the same n such that corresponding Pᵢ
|
| 194 |
+
components are either the same or one is “array of Nᵢ” and the other is
|
| 195 |
+
“array of unknown bound of”, and the types denoted by `U` are the same.
|
| 196 |
|
| 197 |
+
The *qualification-combined type* of two types `T1` and `T2` is the type
|
| 198 |
+
`T3` similar to `T1` whose qualification-decomposition is such that:
|
| 199 |
|
| 200 |
+
- for every i > 0, cv³ᵢ is the union of cv¹ᵢ and cv²ᵢ,
|
| 201 |
- if either P¹ᵢ or P²ᵢ is “array of unknown bound of”, P³ᵢ is “array of
|
| 202 |
+
unknown bound of”, otherwise it is P¹ᵢ, and
|
| 203 |
- if the resulting cv³ᵢ is different from cv¹ᵢ or cv²ᵢ, or the resulting
|
| 204 |
P³ᵢ is different from P¹ᵢ or P²ᵢ, then `const` is added to every cv³ₖ
|
| 205 |
+
for 0 < k < i,
|
| 206 |
|
| 207 |
+
where cvʲᵢ and Pʲᵢ are the components of the qualification-decomposition
|
| 208 |
+
of `T`j. A prvalue of type `T1` can be converted to type `T2` if the
|
| 209 |
+
qualification-combined type of `T1` and `T2` is `T2`.
|
| 210 |
|
| 211 |
[*Note 1*:
|
| 212 |
|
| 213 |
If a program could assign a pointer of type `T**` to a pointer of type
|
| 214 |
`const` `T**` (that is, if line \#1 below were allowed), a program could
|
|
|
|
| 226 |
```
|
| 227 |
|
| 228 |
— *end note*]
|
| 229 |
|
| 230 |
[*Note 2*: Given similar types `T1` and `T2`, this construction ensures
|
| 231 |
+
that both can be converted to the qualification-combined type of `T1`
|
| 232 |
+
and `T2`. — *end note*]
|
| 233 |
|
| 234 |
[*Note 3*: A prvalue of type “pointer to *cv1* `T`” can be converted to
|
| 235 |
a prvalue of type “pointer to *cv2* `T`” if “*cv2* `T`” is more
|
| 236 |
cv-qualified than “*cv1* `T`”. A prvalue of type “pointer to member of
|
| 237 |
`X` of type *cv1* `T`” can be converted to a prvalue of type “pointer to
|
|
|
|
| 242 |
pointer-to-member-function types) are never cv-qualified
|
| 243 |
[[dcl.fct]]. — *end note*]
|
| 244 |
|
| 245 |
### Integral promotions <a id="conv.prom">[[conv.prom]]</a>
|
| 246 |
|
| 247 |
+
A prvalue of an integer type other than `bool`, `char8_t`, `char16_t`,
|
| 248 |
+
`char32_t`, or `wchar_t` whose integer conversion rank [[conv.rank]] is
|
| 249 |
+
less than the rank of `int` can be converted to a prvalue of type `int`
|
| 250 |
+
if `int` can represent all the values of the source type; otherwise, the
|
| 251 |
+
source prvalue can be converted to a prvalue of type `unsigned int`.
|
| 252 |
|
| 253 |
+
A prvalue of type `char8_t`, `char16_t`, `char32_t`, or `wchar_t`
|
| 254 |
[[basic.fundamental]] can be converted to a prvalue of the first of the
|
| 255 |
following types that can represent all the values of its underlying
|
| 256 |
type: `int`, `unsigned int`, `long int`, `unsigned long int`,
|
| 257 |
`long long int`, or `unsigned long long int`. If none of the types in
|
| 258 |
that list can represent all the values of its underlying type, a prvalue
|
| 259 |
+
of type `char8_t`, `char16_t`, `char32_t`, or `wchar_t` can be converted
|
| 260 |
+
to a prvalue of its underlying type.
|
| 261 |
|
| 262 |
A prvalue of an unscoped enumeration type whose underlying type is not
|
| 263 |
fixed can be converted to a prvalue of the first of the following types
|
| 264 |
that can represent all the values of the enumeration [[dcl.enum]]:
|
| 265 |
`int`, `unsigned int`, `long int`, `unsigned long int`, `long long int`,
|
|
|
|
| 280 |
A prvalue for an integral bit-field [[class.bit]] can be converted to a
|
| 281 |
prvalue of type `int` if `int` can represent all the values of the
|
| 282 |
bit-field; otherwise, it can be converted to `unsigned int` if
|
| 283 |
`unsigned int` can represent all the values of the bit-field. If the
|
| 284 |
bit-field is larger yet, no integral promotion applies to it. If the
|
| 285 |
+
bit-field has enumeration type, it is treated as any other value of that
|
| 286 |
+
type for promotion purposes.
|
| 287 |
|
| 288 |
A prvalue of type `bool` can be converted to a prvalue of type `int`,
|
| 289 |
with `false` becoming zero and `true` becoming one.
|
| 290 |
|
| 291 |
These conversions are called *integral promotions*.
|
|
|
|
| 315 |
of integral conversions.
|
| 316 |
|
| 317 |
### Floating-point conversions <a id="conv.double">[[conv.double]]</a>
|
| 318 |
|
| 319 |
A prvalue of floating-point type can be converted to a prvalue of
|
| 320 |
+
another floating-point type with a greater or equal conversion rank
|
| 321 |
+
[[conv.rank]]. A prvalue of standard floating-point type can be
|
| 322 |
+
converted to a prvalue of another standard floating-point type.
|
| 323 |
+
|
| 324 |
+
If the source value can be exactly represented in the destination type,
|
| 325 |
+
the result of the conversion is that exact representation. If the source
|
| 326 |
+
value is between two adjacent destination values, the result of the
|
| 327 |
+
conversion is an *implementation-defined* choice of either of those
|
| 328 |
+
values. Otherwise, the behavior is undefined.
|
| 329 |
|
| 330 |
The conversions allowed as floating-point promotions are excluded from
|
| 331 |
the set of floating-point conversions.
|
| 332 |
|
| 333 |
### Floating-integral conversions <a id="conv.fpint">[[conv.fpint]]</a>
|