With C++20, we are guaranteed two's complement representation for signed integers, and that the conversion from unsigned to signed results in the value that's equal modulo 2^n (cppreference).
You may have encountered messages like “narrowing conversion from ‘unsigned int’ to signed type ‘int’ is implementation-defined”. The C/C++ standard does not mandate two’s complement for signed integers, and so the compiler is free to define what the semantics are for converting an unsigned integer to signed integer.
and this check triggers for code even when compiling for C++20.
<source>:7:20: warning: narrowing conversion from 'uint32_t' (aka 'unsigned int') to signed type 'int32_t' (aka 'int') is implementation-defined [cppcoreguidelines-narrowing-conversions]]
process_signed(val);
^
1 warning generated.
From the documentation page, it doesn't seem like there is an option to just disable just this unsigned->signed check in a C++20 code base.
With C++20, we are guaranteed two's complement representation for signed integers, and that the conversion from unsigned to signed results in the value that's equal modulo 2^n (cppreference).
However, the documentation page for the cppcoreguidelines-narrowing-conversions check still says:
and this check triggers for code even when compiling for C++20.
Sample code (godbolt):
triggers:
From the documentation page, it doesn't seem like there is an option to just disable just this unsigned->signed check in a C++20 code base.
Related to #51855.