From 9bd3fac954ca7a54af6d3757ebfd82038644e0b3 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Tue, 10 Feb 2026 10:57:20 -0500 Subject: [PATCH 1/3] Add test set --- test/Jamfile | 1 + test/github_issue_int128_320.cpp | 55 ++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 test/github_issue_int128_320.cpp diff --git a/test/Jamfile b/test/Jamfile index 57f19c57..e542ed77 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -74,3 +74,4 @@ run github_issue_266.cpp ; run github_issue_267.cpp ; run github_issue_280.cpp ; run github_issue_282.cpp ; +run github_issue_int128_320.cpp ; diff --git a/test/github_issue_int128_320.cpp b/test/github_issue_int128_320.cpp new file mode 100644 index 00000000..dc54a654 --- /dev/null +++ b/test/github_issue_int128_320.cpp @@ -0,0 +1,55 @@ +// Copyright 2026 Matt Borland +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt +// +// See: https://github.com/cppalliance/int128/issues/320 + +#include + +#ifdef BOOST_CHARCONV_HAS_INT128 + +#include +#include +#include + +void toChars(char* ptr, char* ptrEnd, boost::int128_type i128) +{ + auto r = boost::charconv::to_chars(ptr, ptrEnd, i128); + *r.ptr = '\0'; +} + +void toChars(char* ptr, char* ptrEnd, boost::uint128_type u128) +{ + auto r = boost::charconv::to_chars(ptr, ptrEnd, u128); + *r.ptr = '\0'; +} + +int main() +{ + boost::int128_type i128 = -123; + boost::uint128_type u128 = 123; + + std::int64_t ref_value = -123; + + for (int i = 1; i < 5; ++i) + { + i128 *= i; + u128 *= static_cast(i); + ref_value *= i; + + char buf[64] = {}; + toChars(buf, buf + 64, i128); + BOOST_TEST_CSTR_EQ(buf, std::to_string(ref_value).c_str()); + + toChars(buf, buf + 64, u128); + BOOST_TEST_CSTR_EQ(buf, std::to_string(std::abs(ref_value)).c_str()); + }; + + return boost::report_errors(); +} + +#else + +int main() { return 0; } + +#endif From c1e9caad96d21f462e123d8352370313f618c189 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Tue, 10 Feb 2026 10:57:53 -0500 Subject: [PATCH 2/3] Pass unsigned value instead of signed value --- include/boost/charconv/detail/to_chars_integer_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/charconv/detail/to_chars_integer_impl.hpp b/include/boost/charconv/detail/to_chars_integer_impl.hpp index fe42c456..5b256c26 100644 --- a/include/boost/charconv/detail/to_chars_integer_impl.hpp +++ b/include/boost/charconv/detail/to_chars_integer_impl.hpp @@ -270,7 +270,7 @@ BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars_128integer_impl(char* first, c // If the value fits into 64 bits use the other method of processing if (converted_value < (std::numeric_limits::max)()) { - return to_chars_integer_impl(first, last, static_cast(value)); + return to_chars_integer_impl(first, last, static_cast(converted_value)); } constexpr std::uint32_t ten_9 = UINT32_C(1000000000); From f3f60d24f73f9744366bdf3c025cdb8a5da2e361 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Tue, 10 Feb 2026 11:16:28 -0500 Subject: [PATCH 3/3] Ignore GCC-12 stringop overflow warning in test set --- test/github_issue_int128_320.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/github_issue_int128_320.cpp b/test/github_issue_int128_320.cpp index dc54a654..4d4842da 100644 --- a/test/github_issue_int128_320.cpp +++ b/test/github_issue_int128_320.cpp @@ -8,6 +8,11 @@ #ifdef BOOST_CHARCONV_HAS_INT128 +#if defined(__GNUC__) && __GNUC__ == 12 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif + #include #include #include