Re: UBSAN-safe way to convert from unsigned int to int

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2025-05-20 at 10:11 -0400, Andrew Bell via Gcc-help wrote:
> For what it's worth, C++20 defines this behavior:
> 
> 
>    - If the destination type is signed, the value does not change if the
>    source integer can be represented in the destination type. Otherwise the
>    result is implementation-defined(until C++20)the unique value of the
>    destination type equal to the source value modulo 2n
>     where n is the number of bits used to represent the destination type(since
>    C++20) (note that this is different from signed integer arithmetic
>    overflow
>    <https://en.cppreference.com/w/cpp/language/operator_arithmetic#Overflows>,
>    which is undefined).

This is defined even in C89 for any 2's complement target.  The problem
is just Clang insists to add a sanitizer to complain about this.


-- 
Xi Ruoyao <xry111@xxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux