]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Implement C++26 type checking for std::format args [PR115776]
authorJonathan Wakely <jwakely@redhat.com>
Tue, 9 Jul 2024 11:12:56 +0000 (12:12 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 31 Jul 2024 16:07:10 +0000 (17:07 +0100)
commit3836df7e895beda1f159620bfd20024136fda9f0
treec3dc06bb1f742271868e578986f25d91ad741b30
parent72cd15b20a887bed9b0b1f4196be99fe052247b4
libstdc++: Implement C++26 type checking for std::format args [PR115776]

Implement the changes from P2757R3, which enhance the parse context to
be able to do type checking on format arguments, and to use that to
ensure that args used for width and precisions are integral types.

libstdc++-v3/ChangeLog:

PR libstdc++/115776
* include/bits/version.def (format): Update for C++26.
* include/bits/version.h: Regenerate.
* include/std/format (basic_format_parse_context): Remove
default argument from constructor and split into two
constructors. Make the constructor taking size_t private for
C++26 and later.
(basic_format_parse_context::check_dynamic_spec): New member
function template.
(basic_format_parse_context::check_dynamic_spec_integral): New
member function.
(basic_format_parse_context::check_dynamic_spec_string):
Likewise.
(__format::_Spec::_S_parse_width_or_precision): Use
check_dynamic_spec_integral.
(__format::__to_arg_t_enum): New helper function.
(basic_format_arg):  Declare __to_arg_t_enum as friend.
(__format::_Scanner): Define and use a derived parse context
type.
(__format::_Checking_scanner): Make arg types available to parse
context.
* testsuite/std/format/functions/format.cc: Check for new values
of __cpp_lib_format macro.
* testsuite/std/format/parse_ctx.cc: Check all members of
basic_format_parse_context.
* testsuite/std/format/parse_ctx_neg.cc: New test.
* testsuite/std/format/string.cc: Add more checks for dynamic
width and precision args.
libstdc++-v3/include/bits/version.def
libstdc++-v3/include/bits/version.h
libstdc++-v3/include/std/format
libstdc++-v3/testsuite/std/format/functions/format.cc
libstdc++-v3/testsuite/std/format/parse_ctx.cc
libstdc++-v3/testsuite/std/format/parse_ctx_neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/std/format/string.cc