From 085cd7b424cfc1e00054aa88fef015e7f1452f91 Mon Sep 17 00:00:00 2001 From: Ed Catmur Date: Tue, 7 Nov 2023 11:54:53 +0000 Subject: [PATCH] Validity check simple replacement fields (#4078) Co-authored-by: A. Jiang Co-authored-by: Casey Carter --- stl/inc/format | 5 ++++- .../P0645R10_text_formatting_custom_formatting/test.cpp | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/stl/inc/format b/stl/inc/format index a548efe2a7..105307688f 100644 --- a/stl/inc/format +++ b/stl/inc/format @@ -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) { diff --git a/tests/std/tests/P0645R10_text_formatting_custom_formatting/test.cpp b/tests/std/tests/P0645R10_text_formatting_custom_formatting/test.cpp index e15a100d78..928ff8aa89 100644 --- a/tests/std/tests/P0645R10_text_formatting_custom_formatting/test.cpp +++ b/tests/std/tests/P0645R10_text_formatting_custom_formatting/test.cpp @@ -57,7 +57,7 @@ struct not_const_formattable_type { template <> struct std::formatter { - basic_format_parse_context::iterator parse(basic_format_parse_context& parse_ctx) { + constexpr basic_format_parse_context::iterator parse(basic_format_parse_context& parse_ctx) { if (parse_ctx.begin() != parse_ctx.end()) { throw format_error{"only empty specs please"}; } @@ -71,7 +71,7 @@ struct std::formatter { template <> struct std::formatter { - basic_format_parse_context::iterator parse(basic_format_parse_context& parse_ctx) { + constexpr basic_format_parse_context::iterator parse(basic_format_parse_context& parse_ctx) { if (parse_ctx.begin() != parse_ctx.end()) { throw format_error{"only empty specs please"}; }