Skip to content

Commit

Permalink
Validity check simple replacement fields (#4078)
Browse files Browse the repository at this point in the history
Co-authored-by: A. Jiang <de34@live.cn>
Co-authored-by: Casey Carter <cacarter@microsoft.com>
  • Loading branch information
3 people committed Nov 7, 2023
1 parent 900eeac commit 085cd7b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion stl/inc/format
Original file line number Diff line number Diff line change
Expand Up @@ -3579,7 +3579,10 @@ struct _Format_checker {
consteval explicit _Format_checker(basic_string_view<_CharT> _Fmt) noexcept
: _Parse_context(_Fmt, _Num_args), _Parse_funcs{&_Compile_time_parse_format_specs<_Args, _ParseContext>...} {}
constexpr void _On_text(const _CharT*, const _CharT*) const noexcept {}
constexpr void _On_replacement_field(size_t, const _CharT*) const noexcept {}
constexpr void _On_replacement_field(const size_t _Id, const _CharT*) const {
_ParseContext _Parse_ctx({});
(void) _Parse_funcs[_Id](_Parse_ctx);
}
constexpr const _CharT* _On_format_specs(const size_t _Id, const _CharT* _First, const _CharT*) {
_Parse_context.advance_to(_Parse_context.begin() + (_First - _Parse_context.begin()._Unwrapped()));
if (_Id < _Num_args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct not_const_formattable_type {

template <>
struct std::formatter<basic_custom_formattable_type, char> {
basic_format_parse_context<char>::iterator parse(basic_format_parse_context<char>& parse_ctx) {
constexpr basic_format_parse_context<char>::iterator parse(basic_format_parse_context<char>& parse_ctx) {
if (parse_ctx.begin() != parse_ctx.end()) {
throw format_error{"only empty specs please"};
}
Expand All @@ -71,7 +71,7 @@ struct std::formatter<basic_custom_formattable_type, char> {

template <>
struct std::formatter<not_const_formattable_type, char> {
basic_format_parse_context<char>::iterator parse(basic_format_parse_context<char>& parse_ctx) {
constexpr basic_format_parse_context<char>::iterator parse(basic_format_parse_context<char>& parse_ctx) {
if (parse_ctx.begin() != parse_ctx.end()) {
throw format_error{"only empty specs please"};
}
Expand Down

0 comments on commit 085cd7b

Please sign in to comment.