Skip to content

Commit e8b7f92

Browse files
burblebeetkoeppe
authored andcommitted
LWG3720 Restrict the valid types of arg-id for width and precision in std-format-spec
1 parent 3c8ea9e commit e8b7f92

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

source/compatibility.tex

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,24 @@
231231
std::format("{}", t.bit); // ill-formed, previously returned \tcode{"0"}
232232
\end{codeblock}
233233

234+
\diffref{format.string.std}
235+
\change
236+
Restrict types of formatting arguments
237+
used as \fmtgrammarterm{width} or \fmtgrammarterm{precision} in
238+
a \fmtgrammarterm{std-format-spec}.
239+
\rationale
240+
Disallow types that do not have useful or portable semantics as
241+
a formatting width or precision.
242+
\effect
243+
Valid \CppXX{} code that passes a boolean or character type as
244+
\fmtgrammarterm{arg-id} becomes invalid.
245+
For example:
246+
\begin{codeblock}
247+
std::format("{:*^{}}", "", true); // ill-formed, previously returned \tcode{"*"}
248+
std::format("{:*^{}}", "", '1'); // ill-formed, previously returned an
249+
// implementation-defined number of \tcode{'*'} characters
250+
\end{codeblock}
251+
234252
\rSec2[diff.cpp20.strings]{\ref{strings}: strings library}
235253

236254
\diffref{string.classes}

source/utilities.tex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14950,7 +14950,8 @@
1495014950
If \tcode{\{ \opt{\fmtgrammarterm{arg-id}} \}} is used in
1495114951
a \fmtgrammarterm{width} or \fmtgrammarterm{precision},
1495214952
the value of the corresponding formatting argument is used in its place.
14953-
If the corresponding formatting argument is not of integral type, or
14953+
If the corresponding formatting argument is
14954+
not of standard signed or unsigned integer type, or
1495414955
its value is negative,
1495514956
an exception of type \tcode{format_error} is thrown.
1495614957

0 commit comments

Comments
 (0)