[libcxx-commits] [libcxx] [libc++] Suppress unsigned-integer-overflow warning in <charconv> (PR #225801)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Sep 24 00:23:10 PDT 2026


https://github.com/hchataing updated https://github.com/llvm/llvm-project/pull/225801

>From 48a14e9449501d82e7789d027b3be958f1c1d109 Mon Sep 17 00:00:00 2001
From: Henri Chataing <henrichataing at google.com>
Date: Wed, 23 Sep 2026 14:51:23 +0000
Subject: [PATCH] [libc++] Suppress unsigned-integer-overflow warning in
 <charconv>

Invoking __complement with 0 as parameter triggers this runtime error:

> prebuilts/clang/host/linux-x86/clang-r596125/include/c++/v1/__charconv/traits.h:181:19: runtime error: unsigned integer overflow: 18446744073709551615 + 1 cannot be represented in type 'unsigned long'
> SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior prebuilts/clang/host/linux-x86/clang-r596125/include/c++/v1/__charconv/traits.h:181:19
---
 libcxx/include/__charconv/traits.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxx/include/__charconv/traits.h b/libcxx/include/__charconv/traits.h
index b8c840d1ebe326..2f08dac4c2afef 100644
--- a/libcxx/include/__charconv/traits.h
+++ b/libcxx/include/__charconv/traits.h
@@ -155,7 +155,8 @@ struct _LIBCPP_HIDDEN __traits : __traits_base<_Tp> {
 } // namespace __itoa
 
 template <typename _Tp>
-inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI _Tp __complement(_Tp __x) {
+inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
+    _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK _Tp __complement(_Tp __x) {
   static_assert(is_unsigned<_Tp>::value, "cast to unsigned first");
   return _Tp(~__x + 1);
 }



More information about the libcxx-commits mailing list