|
467 | 467 | \nontermdef{member-declarator}\br
|
468 | 468 | declarator virt-specifier-seq\opt pure-specifier\opt\br
|
469 | 469 | declarator brace-or-equal-initializer\opt\br
|
470 |
| - identifier\opt attribute-specifier-seq\opt{} \terminal{:} constant-expression |
| 470 | + identifier\opt{} attribute-specifier-seq\opt{} \terminal{:} constant-expression brace-or-equal-initializer\opt{} |
471 | 471 | \end{bnf}
|
472 | 472 |
|
473 | 473 | \begin{bnf}
|
|
594 | 594 | \end{codeblock}
|
595 | 595 | \end{example}
|
596 | 596 |
|
| 597 | +\pnum |
| 598 | +In a \grammarterm{member-declarator} for a bit-field, |
| 599 | +the \grammarterm{constant-expression} is parsed as |
| 600 | +the longest sequence of tokens |
| 601 | +that could syntactically form a \grammarterm{constant-expression}. |
| 602 | +\begin{example} |
| 603 | +\begin{codeblock} |
| 604 | +int a; |
| 605 | +const int b = 0; |
| 606 | +struct S { |
| 607 | + int x1 : 8 = 42; // OK, \tcode{"= 42"} is \grammarterm{brace-or-equal-initializer} |
| 608 | + int x2 : 8 { 42 }; // OK, \tcode{"\{ 42 \}"} is \grammarterm{brace-or-equal-initializer} |
| 609 | + int y1 : true ? 8 : a = 42; // OK, \grammarterm{brace-or-equal-initializer} is absent |
| 610 | + int y2 : true ? 8 : b = 42; // error: cannot assign to \tcode{const int} |
| 611 | + int y3 : (true ? 8 : b) = 42; // OK, \tcode{"= 42"} is \grammarterm{brace-or-equal-initializer} |
| 612 | + int z : 1 || new int { 0 }; // OK, \grammarterm{brace-or-equal-initializer} is absent |
| 613 | +}; |
| 614 | +\end{codeblock} |
| 615 | +\end{example} |
| 616 | + |
597 | 617 | \pnum
|
598 | 618 | A \grammarterm{brace-or-equal-initializer} shall appear only in the
|
599 | 619 | declaration of a data member. (For static data members,
|
|
1293 | 1313 | A \grammarterm{member-declarator} of the form
|
1294 | 1314 |
|
1295 | 1315 | \begin{ncbnftab}
|
1296 |
| -identifier\opt attribute-specifier-seq\opt{} \terminal{:} constant-expression |
| 1316 | +identifier\opt{} attribute-specifier-seq\opt{} \terminal{:} constant-expression brace-or-equal-initializer\opt{} |
1297 | 1317 | \end{ncbnftab}
|
1298 | 1318 |
|
1299 | 1319 | \indextext{\idxcode{:}!bit-field declaration}%
|
|
0 commit comments