|
74 | 74 | \opt{attribute-specifier-seq} decl-specifier-seq \opt{ref-qualifier} \terminal{[} identifier-list \terminal{]} initializer \terminal{;}
|
75 | 75 | \end{bnf}
|
76 | 76 |
|
| 77 | +\begin{bnf} |
| 78 | +\nontermdef{static_assert-message}\br |
| 79 | + unevaluated-string\br |
| 80 | + conditional-expression |
| 81 | +\end{bnf} |
| 82 | + |
77 | 83 | \begin{bnf}
|
78 | 84 | \nontermdef{static_assert-declaration}\br
|
79 | 85 | \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{;} |
81 | 87 | \end{bnf}
|
82 | 88 |
|
83 | 89 | \begin{bnf}
|
|
250 | 256 | \grammarterm{explicit-specialization}\iref{temp.expl.spec}.
|
251 | 257 | \end{note}
|
252 | 258 |
|
| 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 | + |
253 | 276 | \pnum
|
254 | 277 | \indextext{\idxcode{static_assert}}%
|
255 | 278 | In a \grammarterm{static_assert-declaration},
|
256 |
| -the \grammarterm{constant-expression} |
| 279 | +the \grammarterm{constant-expression} $E$ |
257 | 280 | is contextually converted to \keyword{bool} and
|
258 | 281 | 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. |
268 | 319 | \begin{example}
|
269 | 320 | \begin{codeblock}
|
270 | 321 | static_assert(sizeof(int) == sizeof(void*), "wrong pointer size");
|
|
0 commit comments