Skip to content

Commit 42708d9

Browse files
committed
P0683R1 Default member initializers for bit-fields
1 parent e93d9e0 commit 42708d9

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

source/classes.tex

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@
467467
\nontermdef{member-declarator}\br
468468
declarator virt-specifier-seq\opt pure-specifier\opt\br
469469
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{}
471471
\end{bnf}
472472

473473
\begin{bnf}
@@ -594,6 +594,26 @@
594594
\end{codeblock}
595595
\end{example}
596596

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+
597617
\pnum
598618
A \grammarterm{brace-or-equal-initializer} shall appear only in the
599619
declaration of a data member. (For static data members,
@@ -1293,7 +1313,7 @@
12931313
A \grammarterm{member-declarator} of the form
12941314

12951315
\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{}
12971317
\end{ncbnftab}
12981318

12991319
\indextext{\idxcode{:}!bit-field declaration}%

0 commit comments

Comments
 (0)