libstdc++: Implement P2905R2 "Runtime format strings" for C++20
commit2a8ee2592e48735d88df786cbafa6b0da39fc4d6
authorJonathan Wakely <jwakely@redhat.com>
Sun, 7 Jan 2024 22:21:08 +0000 (7 22:21 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 8 Jan 2024 01:14:50 +0000 (8 01:14 +0000)
tree109224a93e20515d720ae141e87744d512e90fb2
parent37a4c5c23a270cd9350ba5d56e526371424b5742
libstdc++: Implement P2905R2 "Runtime format strings" for C++20

This change makes std::make_format_args refuse to create dangling
references to temporaries. This makes the std::vformat API safer. This
was approved in Kona 2023 as a DR for C++20 so the change is implemented
unconditionally.

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (__formatter_chrono): Always use
lvalue arguments to make_format_args.
* include/std/format (make_format_args): Change parameter pack
from forwarding references to lvalue references. Remove use of
remove_reference_t which is now unnecessary.
(format_to, formatted_size): Remove incorrect forwarding of
arguments.
* include/std/ostream (print): Remove forwarding of arguments.
* include/std/print (print): Likewise.
* testsuite/20_util/duration/io.cc: Use lvalues as arguments to
make_format_args.
* testsuite/std/format/arguments/args.cc: Likewise.
* testsuite/std/format/arguments/lwg3810.cc: Likewise.
* testsuite/std/format/functions/format.cc: Likewise.
* testsuite/std/format/functions/vformat_to.cc: Likewise.
* testsuite/std/format/string.cc: Likewise.
* testsuite/std/time/day/io.cc: Likewise.
* testsuite/std/time/month/io.cc: Likewise.
* testsuite/std/time/weekday/io.cc: Likewise.
* testsuite/std/time/year/io.cc: Likewise.
* testsuite/std/time/year_month_day/io.cc: Likewise.
* testsuite/std/format/arguments/args_neg.cc: New test.
16 files changed:
libstdc++-v3/include/bits/chrono_io.h
libstdc++-v3/include/std/format
libstdc++-v3/include/std/ostream
libstdc++-v3/include/std/print
libstdc++-v3/testsuite/20_util/duration/io.cc
libstdc++-v3/testsuite/std/format/arguments/args.cc
libstdc++-v3/testsuite/std/format/arguments/args_neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/std/format/arguments/lwg3810.cc
libstdc++-v3/testsuite/std/format/functions/format.cc
libstdc++-v3/testsuite/std/format/functions/vformat_to.cc
libstdc++-v3/testsuite/std/format/string.cc
libstdc++-v3/testsuite/std/time/day/io.cc
libstdc++-v3/testsuite/std/time/month/io.cc
libstdc++-v3/testsuite/std/time/weekday/io.cc
libstdc++-v3/testsuite/std/time/year/io.cc
libstdc++-v3/testsuite/std/time/year_month_day/io.cc