From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Add casts for integer-like difference type [PR107871]
Date: Tue, 6 Dec 2022 21:40:54 +0000 [thread overview]
Message-ID: <20221206214054.239631-1-jwakely@redhat.com> (raw)
Tested x86_64-linux. Pushed to trunk.
-- >8 --
libstdc++-v3/ChangeLog:
PR libstdc++/107871
* include/std/format (_Iter_sink::_M_overflow): Add cast to
size_t.
(_Iter_sink<CharT, contiguous_iterator auto>::_M_make_span): Use
typedef instead of decltype.
* testsuite/std/format/functions/107871.cc: New test.
---
libstdc++-v3/include/std/format | 8 ++++----
.../testsuite/std/format/functions/107871.cc | 14 ++++++++++++++
2 files changed, 18 insertions(+), 4 deletions(-)
create mode 100644 libstdc++-v3/testsuite/std/format/functions/107871.cc
diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index 6d6a770eb8c..1072e2c17db 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -2481,12 +2481,12 @@ namespace __format
auto __s = this->_M_used();
if (_M_max < 0) // No maximum.
_M_out = ranges::copy(__s, std::move(_M_out)).out;
- else if (_M_count < size_t(_M_max))
+ else if (_M_count < static_cast<size_t>(_M_max))
{
auto __max = _M_max - _M_count;
span<_CharT> __first;
if (__max < __s.size())
- __first = __s.first(__max);
+ __first = __s.first(static_cast<size_t>(__max));
else
__first = __s;
_M_out = ranges::copy(__first, std::move(_M_out)).out;
@@ -2564,11 +2564,11 @@ namespace __format
if (__n > 0)
{
- if constexpr (!is_integral_v<decltype(__n)>
+ if constexpr (!is_integral_v<iter_difference_t<_OutIter>>
|| sizeof(__n) > sizeof(size_t))
{
// __int128 or __detail::__max_diff_type
- auto __m = (decltype(__n))(size_t)-1;
+ auto __m = iter_difference_t<_OutIter>((size_t)-1);
if (__n > __m)
__n = __m;
}
diff --git a/libstdc++-v3/testsuite/std/format/functions/107871.cc b/libstdc++-v3/testsuite/std/format/functions/107871.cc
new file mode 100644
index 00000000000..1fb558e7ac6
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/format/functions/107871.cc
@@ -0,0 +1,14 @@
+// { dg-options "-std=gnu++20" }
+// { dg-do compile { target c++20 } }
+
+#include <format>
+
+struct O {
+ using difference_type = std::ranges::__detail::__max_diff_type;
+ O& operator=(const char&);
+ O& operator*();
+ O& operator++();
+ O& operator++(int);
+};
+
+auto str = std::format_to_n(O{}, 4, "{}", " "); // PR libstdc++/107871
--
2.38.1
reply other threads:[~2022-12-06 21:41 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221206214054.239631-1-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).