Skip to content

Commit 2fb5999

Browse files
authored
Merge 2023-06 CWG Motion 10
P2741R3 User-generated static_assert messages
2 parents 64306fb + 3d30638 commit 2fb5999

File tree

2 files changed

+63
-12
lines changed

2 files changed

+63
-12
lines changed

source/declarations.tex

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,16 @@
7474
\opt{attribute-specifier-seq} decl-specifier-seq \opt{ref-qualifier} \terminal{[} identifier-list \terminal{]} initializer \terminal{;}
7575
\end{bnf}
7676

77+
\begin{bnf}
78+
\nontermdef{static_assert-message}\br
79+
unevaluated-string\br
80+
conditional-expression
81+
\end{bnf}
82+
7783
\begin{bnf}
7884
\nontermdef{static_assert-declaration}\br
7985
\keyword{static_assert} \terminal{(} constant-expression \terminal{)} \terminal{;}\br
80-
\keyword{static_assert} \terminal{(} constant-expression \terminal{,} unevaluated-string \terminal{)} \terminal{;}
86+
\keyword{static_assert} \terminal{(} constant-expression \terminal{,} static_assert-message \terminal{)} \terminal{;}
8187
\end{bnf}
8288

8389
\begin{bnf}
@@ -250,21 +256,66 @@
250256
\grammarterm{explicit-specialization}\iref{temp.expl.spec}.
251257
\end{note}
252258

259+
\pnum
260+
If a \grammarterm{static_assert-message}
261+
matches the syntactic requirements of \grammarterm{unevaluated-string},
262+
it is an \grammarterm{unevaluated-string} and
263+
the text of the \grammarterm{static_assert-message} is
264+
the text of the \grammarterm{unevaluated-string}.
265+
Otherwise, a \grammarterm{static_assert-message} shall be an expression $M$
266+
such that
267+
\begin{itemize}
268+
\item
269+
the expression \tcode{$M$.size()} is
270+
implicitly convertible to the type \tcode{std::size_t}, and
271+
\item
272+
the expression \tcode{$M$.data()} is
273+
implicitly convertible to the type ``pointer to \tcode{\keyword{const} \keyword{char}}''.
274+
\end{itemize}
275+
253276
\pnum
254277
\indextext{\idxcode{static_assert}}%
255278
In a \grammarterm{static_assert-declaration},
256-
the \grammarterm{constant-expression}
279+
the \grammarterm{constant-expression} $E$
257280
is contextually converted to \keyword{bool} and
258281
the converted expression shall be a constant expression\iref{expr.const}.
259-
If the value of the expression when
260-
so converted is \tcode{true}
261-
or the expression is evaluated in the context of a template definition,
262-
the declaration has no
263-
effect. Otherwise,
264-
the \grammarterm{static_assert-declaration} \defnx{fails}{\idxcode{static_assert}!failed},
265-
the program is ill-formed, and the resulting
266-
diagnostic message\iref{intro.compliance} should include the text of
267-
the \grammarterm{unevaluated-string}, if one is supplied.
282+
If the value of the expression $E$ when so converted is \tcode{true} or
283+
the expression is evaluated in the context of a template definition,
284+
the declaration has no effect and
285+
the \grammarterm{static_assert-message} is
286+
an unevaluated operand\iref{term.unevaluated.operand}.
287+
Otherwise,
288+
the \grammarterm{static_assert-declaration} \defnx{fails}{\idxcode{static_assert}!failed} and
289+
\begin{itemize}
290+
\item
291+
the program is ill-formed, and
292+
\item
293+
if the \grammarterm{static_assert-message} is
294+
a \grammarterm{conditional-expression} $M$,
295+
\begin{itemize}
296+
\item
297+
\tcode{$M$.size()} shall be a converted constant expression of
298+
type \tcode{std::size_t} and
299+
let $N$ denote the value of that expression,
300+
\item
301+
\tcode{$M$.data()}, implicitly converted to
302+
the type ``pointer to \tcode{\keyword{const} \keyword{char}}'',
303+
shall be a core constant expression and let $D$ denote the converted expression,
304+
\item
305+
for each $i$ where $0 \le i < N$,
306+
\tcode{$D$[$i$]} shall be an integral constant expression, and
307+
\item
308+
the text of the \grammarterm{static_assert-message} is formed by
309+
the sequence of $N$ code units, starting at $D$, of
310+
the ordinary literal encoding\iref{lex.charset}.
311+
\end{itemize}
312+
\end{itemize}
313+
314+
\pnum
315+
\recommended
316+
When a \grammarterm{static_assert-declaration} fails,
317+
the resulting diagnostic message should include the text of
318+
the \grammarterm{static_assert-message}, if one is supplied.
268319
\begin{example}
269320
\begin{codeblock}
270321
static_assert(sizeof(int) == sizeof(void*), "wrong pointer size");

source/preprocessor.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1856,7 +1856,7 @@
18561856
\defnxname{cpp_rvalue_references} & \tcode{200610L} \\ \rowsep
18571857
\defnxname{cpp_size_t_suffix} & \tcode{202011L} \\ \rowsep
18581858
\defnxname{cpp_sized_deallocation} & \tcode{201309L} \\ \rowsep
1859-
\defnxname{cpp_static_assert} & \tcode{201411L} \\ \rowsep
1859+
\defnxname{cpp_static_assert} & \tcode{202306L} \\ \rowsep
18601860
\defnxname{cpp_static_call_operator} & \tcode{202207L} \\ \rowsep
18611861
\defnxname{cpp_structured_bindings} & \tcode{201606L} \\ \rowsep
18621862
\defnxname{cpp_template_template_args} & \tcode{201611L} \\ \rowsep

0 commit comments

Comments
 (0)