a575963da9
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
11 lines
2.1 KiB
XML
11 lines
2.1 KiB
XML
<?xml version="1.0"?>
|
|
<clause number="14.16" title="Boolean expressions">
|
|
<paragraph>A <non_terminal where="15.7.1">boolean-expression</non_terminal> is an expression that yields a result of type <keyword>bool</keyword>. <grammar_production><name><non_terminal where="15.7.1">boolean-expression</non_terminal></name> : <rhs><non_terminal where="14.14">expression</non_terminal></rhs></grammar_production></paragraph>
|
|
<paragraph>The controlling conditional expression of an <non_terminal where="15.7.1">if-statement</non_terminal> (<hyperlink>15.7.1</hyperlink>), <non_terminal where="15.8.1">while-statement</non_terminal> (<hyperlink>15.8.1</hyperlink>), <non_terminal where="15.8.2">do-statement</non_terminal> (<hyperlink>15.8.2</hyperlink>), or <non_terminal where="15.8.3">for-statement</non_terminal> (<hyperlink>15.8.3</hyperlink>) is a <non_terminal where="15.7.1">boolean-expression</non_terminal>. The controlling conditional expression of the ?: operator (<hyperlink>14.12</hyperlink>) follows the same rules as a <non_terminal where="15.7.1">boolean-expression</non_terminal>, but for reasons of operator precedence is classified as a <non_terminal where="14.11">conditional-or-expression</non_terminal>. </paragraph>
|
|
<paragraph>A <non_terminal where="15.7.1">boolean-expression</non_terminal> is required to be of a type that can be implicitly converted to <keyword>bool</keyword> or of a type that implements operator true. <note>[Note: As required by <hyperlink>17.9.1</hyperlink>, any type that implements operator true must also implement operator false. end note]</note> If neither requirement is satisfied, a compile-time error occurs. </paragraph>
|
|
<paragraph>When a boolean expression is of a type that cannot be implicitly converted to <keyword>bool</keyword> but does implement operator true, then following evaluation of the expression, the operator true implementation provided by that type is invoked to produce a <keyword>bool</keyword> value. </paragraph>
|
|
<paragraph>
|
|
<note>[Note: The DBBool struct type in <hyperlink>18.4.2</hyperlink> provides an example of a type that implements operator true and operator false. end note]</note>
|
|
</paragraph>
|
|
</clause>
|