<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/60443>60443</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang-tidy: cppcoreguidelines-narrowing-conversions wrongly flags unsigned -> signed conversions in C++20
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          He3lixxx
      </td>
    </tr>
</table>

<pre>
    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](https://en.cppreference.com/w/cpp/language/implicit_conversion#Integral_promotion)).

However, the [documentation page for the cppcoreguidelines-narrowing-conversions](https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/narrowing-conversions.html) check still says:
> 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.

Sample code ([godbolt](https://godbolt.org/z/erfo3rod7)):
```c++
#include <cstdint>

void process_signed(int32_t val);

void caller(uint32_t val) {
    static_assert(__cplusplus >= 202002L, "ensure c++20");
    process_signed(val);
}
```
triggers:
```
<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 this unsigned->signed check.

Related to #51855.


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVk1v6jgX_jVmcwQKx6SBBQsoRfeV3tXMSKNZIWMfEt_r2BnbgTK_fuR8FLh0rlq1lNjn8znPY0eEoEtLtGb5luW7iWhj5fz6G3Gj39_fJ0enrus_dazgleGW4RYzhq9w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