tmp/tmp2y_q0yuk/{from.md → to.md}
RENAMED
|
@@ -117,16 +117,17 @@ if (x) {
|
|
| 117 |
|
| 118 |
Thus after the `if` statement, `i` is no longer in scope.
|
| 119 |
|
| 120 |
The rules for *condition*s apply both to *selection-statement*s and to
|
| 121 |
the `for` and `while` statements ([[stmt.iter]]). The *declarator*
|
| 122 |
-
shall not specify a function or an array.
|
| 123 |
-
|
| 124 |
-
|
|
|
|
| 125 |
|
| 126 |
A name introduced by a declaration in a *condition* (either introduced
|
| 127 |
-
by the *
|
| 128 |
scope from its point of declaration until the end of the substatements
|
| 129 |
controlled by the condition. If the name is re-declared in the outermost
|
| 130 |
block of a substatement controlled by the condition, the declaration
|
| 131 |
that re-declares the name is ill-formed.
|
| 132 |
|
|
@@ -162,37 +163,37 @@ shall be either a *type-specifier* or `constexpr`.
|
|
| 162 |
### The `if` statement <a id="stmt.if">[[stmt.if]]</a>
|
| 163 |
|
| 164 |
If the condition ([[stmt.select]]) yields `true` the first substatement
|
| 165 |
is executed. If the `else` part of the selection statement is present
|
| 166 |
and the condition yields `false`, the second substatement is executed.
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
statement
|
|
|
|
|
|
|
| 170 |
|
| 171 |
### The `switch` statement <a id="stmt.switch">[[stmt.switch]]</a>
|
| 172 |
|
| 173 |
The `switch` statement causes control to be transferred to one of
|
| 174 |
several statements depending on the value of a condition.
|
| 175 |
|
| 176 |
-
The condition shall be of integral type, enumeration type, or
|
| 177 |
-
type
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
with one or more case labels as follows:
|
| 184 |
|
| 185 |
``` bnf
|
| 186 |
'case' constant-expression ':'
|
| 187 |
```
|
| 188 |
|
| 189 |
where the *constant-expression* shall be a converted constant
|
| 190 |
-
expression ([[expr.const]]) of the
|
| 191 |
condition. No two of the case constants in the same switch shall have
|
| 192 |
-
the same value after conversion
|
| 193 |
-
condition.
|
| 194 |
|
| 195 |
There shall be at most one label of the form
|
| 196 |
|
| 197 |
``` cpp
|
| 198 |
default :
|
|
@@ -344,25 +345,25 @@ The `for` statement
|
|
| 344 |
```
|
| 345 |
|
| 346 |
is equivalent to
|
| 347 |
|
| 348 |
except that names declared in the *for-init-statement* are in the same
|
| 349 |
-
declarative
|
| 350 |
a `continue` in *statement* (not enclosed in another iteration
|
| 351 |
statement) will execute *expression* before re-evaluating *condition*.
|
| 352 |
Thus the first statement specifies initialization for the loop; the
|
| 353 |
condition ([[stmt.select]]) specifies a test, made before each
|
| 354 |
iteration, such that the loop is exited when the condition becomes
|
| 355 |
`false`; the expression often specifies incrementing that is done after
|
| 356 |
each iteration.
|
| 357 |
|
| 358 |
Either or both of the condition and the expression can be omitted. A
|
| 359 |
-
missing *condition* makes the implied `while`
|
| 360 |
`while(true)`.
|
| 361 |
|
| 362 |
If the *for-init-statement* is a declaration, the scope of the name(s)
|
| 363 |
-
declared extends to the end of the
|
| 364 |
|
| 365 |
``` cpp
|
| 366 |
int i = 42;
|
| 367 |
int a[10];
|
| 368 |
|
|
@@ -421,23 +422,23 @@ exposition only, and `_RangeT` is the type of the *expression*, and
|
|
| 421 |
are looked up in the scope of class `\mbox{_RangeT}` as if by class
|
| 422 |
member access lookup ([[basic.lookup.classref]]), and if either (or
|
| 423 |
both) finds at least one declaration, *begin-expr* and *end-expr* are
|
| 424 |
`__range.begin()` and `__range.end()`, respectively;
|
| 425 |
- otherwise, *begin-expr* and *end-expr* are `begin(__range)` and
|
| 426 |
-
`end(__range)`, respectively, where `begin` and `end` are looked up
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
namespace.
|
| 430 |
|
| 431 |
``` cpp
|
| 432 |
int array[5] = { 1, 2, 3, 4, 5 };
|
| 433 |
for (int& x : array)
|
| 434 |
x *= 2;
|
| 435 |
```
|
| 436 |
|
| 437 |
In the *decl-specifier-seq* of a *for-range-declaration*, each
|
| 438 |
-
*decl-specifier* shall be either a *type-specifier* or `constexpr`.
|
|
|
|
| 439 |
|
| 440 |
## Jump statements <a id="stmt.jump">[[stmt.jump]]</a>
|
| 441 |
|
| 442 |
Jump statements unconditionally transfer control.
|
| 443 |
|
|
@@ -510,17 +511,17 @@ equivalent to `goto` `contin`.
|
|
| 510 |
|
| 511 |
A function returns to its caller by the `return` statement.
|
| 512 |
|
| 513 |
A return statement with neither an *expression* nor a *braced-init-list*
|
| 514 |
can be used only in functions that do not return a value, that is, a
|
| 515 |
-
function with the return type `void`, a constructor (
|
| 516 |
-
or a destructor ([[class.dtor]]). A return statement
|
| 517 |
-
of non-void type can be used only in functions
|
| 518 |
-
value of the expression is returned to the caller
|
| 519 |
-
value of the expression is implicitly converted to
|
| 520 |
-
the function in which it appears. A return statement
|
| 521 |
-
construction and copy or move of a temporary object (
|
| 522 |
[[class.temporary]]). A copy or move operation associated with a return
|
| 523 |
statement may be elided or considered as an rvalue for the purpose of
|
| 524 |
overload resolution in selecting a constructor ([[class.copy]]). A
|
| 525 |
return statement with a *braced-init-list* initializes the object or
|
| 526 |
reference to be returned from the function by copy-list-initialization (
|
|
@@ -626,14 +627,17 @@ with static and thread storage duration are destroyed.
|
|
| 626 |
There is an ambiguity in the grammar involving *expression-statement*s
|
| 627 |
and *declaration*s: An *expression-statement* with a function-style
|
| 628 |
explicit type conversion ([[expr.type.conv]]) as its leftmost
|
| 629 |
subexpression can be indistinguishable from a *declaration* where the
|
| 630 |
first *declarator* starts with a `(`. In those cases the *statement* is
|
| 631 |
-
a *declaration*.
|
| 632 |
-
|
| 633 |
-
*
|
| 634 |
-
*
|
|
|
|
|
|
|
|
|
|
| 635 |
|
| 636 |
``` cpp
|
| 637 |
T(a)->m = 7; // expression-statement
|
| 638 |
T(a)++; // expression-statement
|
| 639 |
T(a,5)<<c; // expression-statement
|
|
@@ -700,23 +704,24 @@ void f() {
|
|
| 700 |
```
|
| 701 |
|
| 702 |
<!-- Link reference definitions -->
|
| 703 |
[basic.lookup.argdep]: basic.md#basic.lookup.argdep
|
| 704 |
[basic.lookup.classref]: basic.md#basic.lookup.classref
|
|
|
|
| 705 |
[basic.scope]: basic.md#basic.scope
|
| 706 |
[basic.scope.pdecl]: basic.md#basic.scope.pdecl
|
| 707 |
[basic.start.init]: basic.md#basic.start.init
|
| 708 |
[basic.start.term]: basic.md#basic.start.term
|
| 709 |
[basic.stc.auto]: basic.md#basic.stc.auto
|
| 710 |
[basic.stc.static]: basic.md#basic.stc.static
|
| 711 |
[basic.stc.thread]: basic.md#basic.stc.thread
|
| 712 |
-
[class.conv]: special.md#class.conv
|
| 713 |
[class.copy]: special.md#class.copy
|
| 714 |
[class.ctor]: special.md#class.ctor
|
| 715 |
[class.dtor]: special.md#class.dtor
|
| 716 |
[class.temporary]: special.md#class.temporary
|
| 717 |
[conv]: conv.md#conv
|
|
|
|
| 718 |
[dcl.init]: dcl.md#dcl.init
|
| 719 |
[dcl.init.list]: dcl.md#dcl.init.list
|
| 720 |
[dcl.meaning]: dcl.md#dcl.meaning
|
| 721 |
[dcl.spec.auto]: dcl.md#dcl.spec.auto
|
| 722 |
[dcl.type]: dcl.md#dcl.type
|
|
|
|
| 117 |
|
| 118 |
Thus after the `if` statement, `i` is no longer in scope.
|
| 119 |
|
| 120 |
The rules for *condition*s apply both to *selection-statement*s and to
|
| 121 |
the `for` and `while` statements ([[stmt.iter]]). The *declarator*
|
| 122 |
+
shall not specify a function or an array. The *decl-specifier-seq* shall
|
| 123 |
+
not define a class or enumeration. If the `auto` appears in the , the
|
| 124 |
+
type of the identifier being declared is deduced from the initializer as
|
| 125 |
+
described in [[dcl.spec.auto]].
|
| 126 |
|
| 127 |
A name introduced by a declaration in a *condition* (either introduced
|
| 128 |
+
by the *decl-specifier-seq* or the *declarator* of the condition) is in
|
| 129 |
scope from its point of declaration until the end of the substatements
|
| 130 |
controlled by the condition. If the name is re-declared in the outermost
|
| 131 |
block of a substatement controlled by the condition, the declaration
|
| 132 |
that re-declares the name is ill-formed.
|
| 133 |
|
|
|
|
| 163 |
### The `if` statement <a id="stmt.if">[[stmt.if]]</a>
|
| 164 |
|
| 165 |
If the condition ([[stmt.select]]) yields `true` the first substatement
|
| 166 |
is executed. If the `else` part of the selection statement is present
|
| 167 |
and the condition yields `false`, the second substatement is executed.
|
| 168 |
+
If the first substatement is reached via a label, the condition is not
|
| 169 |
+
evaluated and the second substatement is not executed. In the second
|
| 170 |
+
form of `if` statement (the one including `else`), if the first
|
| 171 |
+
substatement is also an `if` statement then that inner `if` statement
|
| 172 |
+
shall contain an `else` part.[^1]
|
| 173 |
|
| 174 |
### The `switch` statement <a id="stmt.switch">[[stmt.switch]]</a>
|
| 175 |
|
| 176 |
The `switch` statement causes control to be transferred to one of
|
| 177 |
several statements depending on the value of a condition.
|
| 178 |
|
| 179 |
+
The condition shall be of integral type, enumeration type, or class
|
| 180 |
+
type. If of class type, the condition is contextually implicitly
|
| 181 |
+
converted (Clause [[conv]]) to an integral or enumeration type. If the
|
| 182 |
+
(possibly converted) type is subject to integral promotions (
|
| 183 |
+
[[conv.prom]]), the condition is converted to the promoted type. Any
|
| 184 |
+
statement within the `switch` statement can be labeled with one or more
|
| 185 |
+
case labels as follows:
|
|
|
|
| 186 |
|
| 187 |
``` bnf
|
| 188 |
'case' constant-expression ':'
|
| 189 |
```
|
| 190 |
|
| 191 |
where the *constant-expression* shall be a converted constant
|
| 192 |
+
expression ([[expr.const]]) of the adjusted type of the switch
|
| 193 |
condition. No two of the case constants in the same switch shall have
|
| 194 |
+
the same value after conversion.
|
|
|
|
| 195 |
|
| 196 |
There shall be at most one label of the form
|
| 197 |
|
| 198 |
``` cpp
|
| 199 |
default :
|
|
|
|
| 345 |
```
|
| 346 |
|
| 347 |
is equivalent to
|
| 348 |
|
| 349 |
except that names declared in the *for-init-statement* are in the same
|
| 350 |
+
declarative region as those declared in the *condition*, and except that
|
| 351 |
a `continue` in *statement* (not enclosed in another iteration
|
| 352 |
statement) will execute *expression* before re-evaluating *condition*.
|
| 353 |
Thus the first statement specifies initialization for the loop; the
|
| 354 |
condition ([[stmt.select]]) specifies a test, made before each
|
| 355 |
iteration, such that the loop is exited when the condition becomes
|
| 356 |
`false`; the expression often specifies incrementing that is done after
|
| 357 |
each iteration.
|
| 358 |
|
| 359 |
Either or both of the condition and the expression can be omitted. A
|
| 360 |
+
missing *condition* makes the implied `while` clause equivalent to
|
| 361 |
`while(true)`.
|
| 362 |
|
| 363 |
If the *for-init-statement* is a declaration, the scope of the name(s)
|
| 364 |
+
declared extends to the end of the `for` statement.
|
| 365 |
|
| 366 |
``` cpp
|
| 367 |
int i = 42;
|
| 368 |
int a[10];
|
| 369 |
|
|
|
|
| 422 |
are looked up in the scope of class `\mbox{_RangeT}` as if by class
|
| 423 |
member access lookup ([[basic.lookup.classref]]), and if either (or
|
| 424 |
both) finds at least one declaration, *begin-expr* and *end-expr* are
|
| 425 |
`__range.begin()` and `__range.end()`, respectively;
|
| 426 |
- otherwise, *begin-expr* and *end-expr* are `begin(__range)` and
|
| 427 |
+
`end(__range)`, respectively, where `begin` and `end` are looked up in
|
| 428 |
+
the associated namespaces ([[basic.lookup.argdep]]). Ordinary
|
| 429 |
+
unqualified lookup ([[basic.lookup.unqual]]) is not performed.
|
|
|
|
| 430 |
|
| 431 |
``` cpp
|
| 432 |
int array[5] = { 1, 2, 3, 4, 5 };
|
| 433 |
for (int& x : array)
|
| 434 |
x *= 2;
|
| 435 |
```
|
| 436 |
|
| 437 |
In the *decl-specifier-seq* of a *for-range-declaration*, each
|
| 438 |
+
*decl-specifier* shall be either a *type-specifier* or `constexpr`. The
|
| 439 |
+
*decl-specifier-seq* shall not define a class or enumeration.
|
| 440 |
|
| 441 |
## Jump statements <a id="stmt.jump">[[stmt.jump]]</a>
|
| 442 |
|
| 443 |
Jump statements unconditionally transfer control.
|
| 444 |
|
|
|
|
| 511 |
|
| 512 |
A function returns to its caller by the `return` statement.
|
| 513 |
|
| 514 |
A return statement with neither an *expression* nor a *braced-init-list*
|
| 515 |
can be used only in functions that do not return a value, that is, a
|
| 516 |
+
function with the return type cv `void`, a constructor (
|
| 517 |
+
[[class.ctor]]), or a destructor ([[class.dtor]]). A return statement
|
| 518 |
+
with an expression of non-void type can be used only in functions
|
| 519 |
+
returning a value; the value of the expression is returned to the caller
|
| 520 |
+
of the function. The value of the expression is implicitly converted to
|
| 521 |
+
the return type of the function in which it appears. A return statement
|
| 522 |
+
can involve the construction and copy or move of a temporary object (
|
| 523 |
[[class.temporary]]). A copy or move operation associated with a return
|
| 524 |
statement may be elided or considered as an rvalue for the purpose of
|
| 525 |
overload resolution in selecting a constructor ([[class.copy]]). A
|
| 526 |
return statement with a *braced-init-list* initializes the object or
|
| 527 |
reference to be returned from the function by copy-list-initialization (
|
|
|
|
| 627 |
There is an ambiguity in the grammar involving *expression-statement*s
|
| 628 |
and *declaration*s: An *expression-statement* with a function-style
|
| 629 |
explicit type conversion ([[expr.type.conv]]) as its leftmost
|
| 630 |
subexpression can be indistinguishable from a *declaration* where the
|
| 631 |
first *declarator* starts with a `(`. In those cases the *statement* is
|
| 632 |
+
a *declaration*.
|
| 633 |
+
|
| 634 |
+
If the *statement* cannot syntactically be a *declaration*, there is no
|
| 635 |
+
ambiguity, so this rule does not apply. The whole *statement* might need
|
| 636 |
+
to be examined to determine whether this is the case. This resolves the
|
| 637 |
+
meaning of many examples. Assuming `T` is a *simple-type-specifier* (
|
| 638 |
+
[[dcl.type]]),
|
| 639 |
|
| 640 |
``` cpp
|
| 641 |
T(a)->m = 7; // expression-statement
|
| 642 |
T(a)++; // expression-statement
|
| 643 |
T(a,5)<<c; // expression-statement
|
|
|
|
| 704 |
```
|
| 705 |
|
| 706 |
<!-- Link reference definitions -->
|
| 707 |
[basic.lookup.argdep]: basic.md#basic.lookup.argdep
|
| 708 |
[basic.lookup.classref]: basic.md#basic.lookup.classref
|
| 709 |
+
[basic.lookup.unqual]: basic.md#basic.lookup.unqual
|
| 710 |
[basic.scope]: basic.md#basic.scope
|
| 711 |
[basic.scope.pdecl]: basic.md#basic.scope.pdecl
|
| 712 |
[basic.start.init]: basic.md#basic.start.init
|
| 713 |
[basic.start.term]: basic.md#basic.start.term
|
| 714 |
[basic.stc.auto]: basic.md#basic.stc.auto
|
| 715 |
[basic.stc.static]: basic.md#basic.stc.static
|
| 716 |
[basic.stc.thread]: basic.md#basic.stc.thread
|
|
|
|
| 717 |
[class.copy]: special.md#class.copy
|
| 718 |
[class.ctor]: special.md#class.ctor
|
| 719 |
[class.dtor]: special.md#class.dtor
|
| 720 |
[class.temporary]: special.md#class.temporary
|
| 721 |
[conv]: conv.md#conv
|
| 722 |
+
[conv.prom]: conv.md#conv.prom
|
| 723 |
[dcl.init]: dcl.md#dcl.init
|
| 724 |
[dcl.init.list]: dcl.md#dcl.init.list
|
| 725 |
[dcl.meaning]: dcl.md#dcl.meaning
|
| 726 |
[dcl.spec.auto]: dcl.md#dcl.spec.auto
|
| 727 |
[dcl.type]: dcl.md#dcl.type
|