Стандарт C++ 98 (1119566), страница 31
Текст из файла (страница 31)
An expression that designates the address of a member or base class of a non-POD class object (clause 9) is not anaddress constant expression (12.7). Function calls shall not be used in an address constant expression, evenif the function is inline and has a reference return type.5A reference constant expression is an lvalue designating an object of static storage duration, a non-typetemplate parameter of reference type, or a function. The subscripting operator [], the class member access.
and -> operators, the & and * unary operators, and reference casts (except those invoking user-definedconversion functions (12.3.2) and except dynamic_casts (5.2.7)) can be used in the creation of a reference constant expression, but the value of an object shall not be accessed by the use of these operators. Ifthe subscripting operator is used, one of its operands shall be an integral constant expression. An lvalueexpression that designates a member or base class of a non-POD class object (clause 9) is not a referenceconstant expression (12.7). Function calls shall not be used in a reference constant expression, even if thefunction is inline and has a reference return type.6A pointer to member constant expression shall be created using the unary & operator applied to a qualifiedid operand (5.3.1), optionally preceded by a pointer to member cast (5.2.9).91ISO/IEC 14882:1998(E)©(Blank page)92ISO/IEC© ISO/IECISO/IEC 14882:1998(E)6 Statements6 Statements6 Statements1[stmt.stmt]Except as indicated, statements are executed in sequence.statement:labeled-statementexpression-statementcompound-statementselection-statementiteration-statementjump-statementdeclaration-statementtry-block6.1 Labeled statement1[stmt.label]A statement can be labeled.labeled-statement:identifier : statementcase constant-expression : statementdefault : statementAn identifier label declares the identifier.
The only use of an identifier label is as the target of a goto. Thescope of a label is the function in which it appears. Labels shall not be redeclared within a function. Alabel can be used in a goto statement before its definition. Labels have their own name space and do notinterfere with other identifiers.2Case labels and default labels shall occur only in switch statements.6.2 Expression statement1[stmt.expr]Expression statements have the formexpression-statement:expressionopt ;The expression is evaluated and its value is discarded.
The lvalue-to-rvalue (4.1), array-to-pointer (4.2),and function-to-pointer (4.3) standard conversions are not applied to the expression. All side effects froman expression statement are completed before the next statement is executed. An expression statement withthe expression missing is called a null statement. [Note: Most statements are expression statements—usually assignments or function calls.
A null statement is useful to carry a label just before the } of a compound statement and to supply a null body to an iteration statement such as a while statement (6.5.1). ]6.3 Compound statement or block1[stmt.block]So that several statements can be used where one is expected, the compound statement (also, and equivalently, called “block”) is provided.compound-statement:{ statement-seqopt }statement-seq:statementstatement-seq statementA compound statement defines a local scope (3.3).
[Note: a declaration is a statement (6.7). ]93ISO/IEC 14882:1998(E)1© ISO/IEC6.4 Selection statements6 Statements6.4 Selection statements[stmt.select]Selection statements choose one of several flows of control.selection-statement:if ( condition ) statementif ( condition ) statement else statementswitch ( condition ) statementcondition:expressiontype-specifier-seq declarator = assignment-expressionIn clause 6, the term substatement refers to the contained statement or statements that appear in the syntaxnotation.
The substatement in a selection-statement (both substatements, in the else form of the if statement) implicitly defines a local scope (3.3). If the substatement in a selection-statement is a single statement and not a compound-statement, it is as if it was rewritten to be a compound-statement containing theoriginal substatement. [Example:if (x)int i;can be equivalently rewritten asif (x) {int i;}Thus after the if statement, i is no longer in scope.
]2The rules for conditions apply both to selection-statements and to the for and while statements (6.5).The declarator shall not specify a function or an array. The type-specifier-seq shall not contain typedefand shall not declare a new class or enumeration.3A name introduced by a declaration in a condition (either introduced by the type-specifier-seq or thedeclarator of the condition) is in scope from its point of declaration until the end of the substatements controlled by the condition. If the name is re-declared in the outermost block of a substatement controlled bythe condition, the declaration that re-declares the name is ill-formed.
[Example:if (int x = f()) {int x;}else {int x;}// ill-formed, redeclaration of x// ill-formed, redeclaration of x—end example]4The value of a condition that is an initialized declaration in a statement other than a switch statement isthe value of the declared variable implicitly converted to type bool. If that conversion is ill-formed, theprogram is ill-formed. The value of a condition that is an initialized declaration in a switch statement isthe value of the declared variable if it has integral or enumeration type, or of that variable implicitly converted to integral or enumeration type otherwise. The value of a condition that is an expression is the valueof the expression, implicitly converted to bool for statements other than switch; if that conversion isill-formed, the program is ill-formed.
The value of the condition will be referred to as simply “the condition” where the usage is unambiguous.5If a condition can be syntactically resolved as either an expression or the declaration of a local name, it isinterpreted as a declaration.94© ISO/IECISO/IEC 14882:1998(E)6 Statements6.4.1 The if statement6.4.1 The if statement1[stmt.if]If the condition (6.4) yields true the first substatement is executed. If the else part of the selectionstatement is present and the condition yields false, the second substatement is executed.
In the secondform of if statement (the one including else), if the first substatement is also an if statement then thatinner if statement shall contain an else part.76)6.4.2 The switch statement[stmt.switch]1The switch statement causes control to be transferred to one of several statements depending on the valueof a condition.2The condition shall be of integral type, enumeration type, or of a class type for which a single conversionfunction to integral or enumeration type exists (12.3). If the condition is of class type, the condition is converted by calling that conversion function, and the result of the conversion is used in place of the originalcondition for the remainder of this section.
Integral promotions are performed. Any statement within theswitch statement can be labeled with one or more case labels as follows:case constant-expression :where the constant-expression shall be an integral constant-expression. The integral constant-expression(5.19) is implicitly converted to the promoted type of the switch condition. No two of the case constants inthe same switch shall have the same value after conversion to the promoted type of the switch condition.3There shall be at most one label of the formdefault :within a switch statement.4Switch statements can be nested; a case or default label is associated with the smallest switch enclosing it.5When the switch statement is executed, its condition is evaluated and compared with each case constant.If one of the case constants is equal to the value of the condition, control is passed to the statement following the matched case label.
If no case constant matches the condition, and if there is a default label,control passes to the statement labeled by the default label. If no case matches and if there is no defaultthen none of the statements in the switch is executed.6case and default labels in themselves do not alter the flow of control, which continues unimpededacross such labels. To exit from a switch, see break, 6.6.1. [Note: usually, the substatement that is thesubject of a switch is compound and case and default labels appear on the top-level statements contained within the (compound) substatement, but this is not required. Declarations can appear in the substatement of a switch-statement. ]6.5 Iteration statements1[stmt.iter]Iteration statements specify looping.iteration-statement:while ( condition ) statementdo statement while ( expression ) ;for ( for-init-statement conditionopt ; expressionopt ) statementfor-init-statement:expression-statementsimple-declaration[Note: a for-init-statement ends with a semicolon.
]__________________76) In other words, the else is associated with the nearest un-elsed if.95ISO/IEC 14882:1998(E)© ISO/IEC6.5 Iteration statements6 Statements2The substatement in an iteration-statement implicitly defines a local scope (3.3) which is entered and exitedeach time through the loop.3If the substatement in an iteration-statement is a single statement and not a compound-statement, it is as if itwas rewritten to be a compound-statement containing the original statement. [Example:while (--x >= 0)int i;can be equivalently rewritten aswhile (--x >= 0) {int i;}Thus after the while statement, i is no longer in scope.