Skip to content

Commit cab1a25

Browse files
committed
P2757R3 Type checking format args
1 parent d544cfc commit cab1a25

File tree

2 files changed

+80
-9
lines changed

2 files changed

+80
-9
lines changed

source/support.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@
624624
#define @\defnlibxname{cpp_lib_filesystem}@ 201703L // also in \libheader{filesystem}
625625
#define @\defnlibxname{cpp_lib_flat_map}@ 202207L // also in \libheader{flat_map}
626626
#define @\defnlibxname{cpp_lib_flat_set}@ 202207L // also in \libheader{flat_set}
627-
#define @\defnlibxname{cpp_lib_format}@ 202207L // also in \libheader{format}
627+
#define @\defnlibxname{cpp_lib_format}@ 202306L // also in \libheader{format}
628628
#define @\defnlibxname{cpp_lib_format_ranges}@ 202207L // also in \libheader{format}
629629
#define @\defnlibxname{cpp_lib_formatters}@ 202302L // also in \libheader{stacktrace}, \libheader{thread}
630630
#define @\defnlibxname{cpp_lib_forward_like}@ 202207L // also in \libheader{utility}

source/utilities.tex

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15065,9 +15065,9 @@
1506515065
If \tcode{\{ \opt{\fmtgrammarterm{arg-id}} \}} is used in
1506615066
a \fmtgrammarterm{width} or \fmtgrammarterm{precision} option,
1506715067
the value of the corresponding formatting argument is used as the value of the option.
15068-
If the corresponding formatting argument is
15069-
not of standard signed or unsigned integer type, or
15070-
its value is negative,
15068+
The option is valid only if the corresponding formatting argument is
15069+
of standard signed or unsigned integer type.
15070+
If its value is negative,
1507115071
an exception of type \tcode{format_error} is thrown.
1507215072

1507315073
\pnum
@@ -16173,8 +16173,7 @@
1617316173
size_t num_args_; // \expos
1617416174

1617516175
public:
16176-
constexpr explicit basic_format_parse_context(basic_string_view<charT> fmt,
16177-
size_t num_args = 0) noexcept;
16176+
constexpr explicit basic_format_parse_context(basic_string_view<charT> fmt) noexcept;
1617816177
basic_format_parse_context(const basic_format_parse_context&) = delete;
1617916178
basic_format_parse_context& operator=(const basic_format_parse_context&) = delete;
1618016179

@@ -16184,6 +16183,11 @@
1618416183

1618516184
constexpr size_t next_arg_id();
1618616185
constexpr void check_arg_id(size_t id);
16186+
16187+
template<class... Ts>
16188+
constexpr void check_dynamic_spec(size_t id) noexcept;
16189+
constexpr void check_dynamic_spec_integral(size_t id) noexcept;
16190+
constexpr void check_dynamic_spec_string(size_t id) noexcept;
1618716191
};
1618816192
}
1618916193
\end{codeblock}
@@ -16196,8 +16200,7 @@
1619616200

1619716201
\indexlibraryctor{basic_format_parse_context}%
1619816202
\begin{itemdecl}
16199-
constexpr explicit basic_format_parse_context(basic_string_view<charT> fmt,
16200-
size_t num_args = 0) noexcept;
16203+
constexpr explicit basic_format_parse_context(basic_string_view<charT> fmt) noexcept;
1620116204
\end{itemdecl}
1620216205

1620316206
\begin{itemdescr}
@@ -16208,7 +16211,13 @@
1620816211
\tcode{end_} with \tcode{fmt.end()},
1620916212
\tcode{indexing_} with \tcode{unknown},
1621016213
\tcode{next_arg_id_} with \tcode{0}, and
16211-
\tcode{num_args_} with \tcode{num_args}.
16214+
\tcode{num_args_} with \tcode{0}.
16215+
\begin{note}
16216+
Any call to
16217+
\tcode{next_arg_id}, \tcode{check_arg_id}, or \tcode{check_dynamic_spec}
16218+
on an instance of \tcode{basic_format_parse_context}
16219+
initialized using this constructor is not a core constant expression.
16220+
\end{note}
1621216221
\end{itemdescr}
1621316222

1621416223
\indexlibrarymember{begin}{basic_format_parse_context}%
@@ -16301,6 +16310,68 @@
1630116310
core constant expressions\iref{expr.const}.
1630216311
\end{itemdescr}
1630316312

16313+
\indexlibrarymember{check_dynamic_spec}{basic_format_parse_context}%
16314+
\begin{itemdecl}
16315+
template<class... Ts>
16316+
constexpr void check_dynamic_spec(size_t id) noexcept;
16317+
\end{itemdecl}
16318+
16319+
\begin{itemdescr}
16320+
\pnum
16321+
\mandates
16322+
The types in \tcode{Ts...} are unique.
16323+
Each type in \tcode{Ts...} is one of
16324+
\keyword{bool},
16325+
\tcode{char_type},
16326+
\keyword{int},
16327+
\keyword{unsigned} \keyword{int},
16328+
\keyword{long} \keyword{long} \keyword{int},
16329+
\keyword{unsigned} \keyword{long} \keyword{long} \keyword{int},
16330+
\keyword{float},
16331+
\keyword{double},
16332+
\keyword{long} \keyword{double},
16333+
\tcode{\keyword{const} char_type*},
16334+
\tcode{basic_string_view<char_type>}, or
16335+
\tcode{\keyword{const} \keyword{void}*}.
16336+
16337+
\pnum
16338+
\remarks
16339+
Call expressions where
16340+
\tcode{id >= num_args_} or
16341+
the type of the corresponding format argument
16342+
(after conversion to \tcode{basic_format_arg<Context>})
16343+
is not one of the types in \tcode{Ts...}
16344+
are not core constant expressions\iref{expr.const}.
16345+
\end{itemdescr}
16346+
16347+
\indexlibrarymember{check_dynamic_spec}{basic_format_parse_context}%
16348+
\begin{itemdecl}
16349+
constexpr void check_dynamic_spec_integral(size_t id) noexcept;
16350+
\end{itemdecl}
16351+
16352+
\begin{itemdescr}
16353+
\pnum
16354+
\effects
16355+
Equivalent to:
16356+
\begin{codeblock}
16357+
check_dynamic_spec<int, unsigned int, long long int, unsigned long long int>(id);
16358+
\end{codeblock}
16359+
\end{itemdescr}
16360+
16361+
\indexlibrarymember{check_dynamic_spec}{basic_format_parse_context}%
16362+
\begin{itemdecl}
16363+
constexpr void check_dynamic_spec_string(size_t id) noexcept;
16364+
\end{itemdecl}
16365+
16366+
\begin{itemdescr}
16367+
\pnum
16368+
\effects
16369+
Equivalent to:
16370+
\begin{codeblock}
16371+
check_dynamic_spec<const char_type*, basic_string_view<char_type>>(id);
16372+
\end{codeblock}
16373+
\end{itemdescr}
16374+
1630416375
\rSec3[format.context]{Class template \tcode{basic_format_context}}
1630516376

1630616377
\indexlibraryglobal{basic_format_context}%

0 commit comments

Comments
 (0)