[clang] [Clang] Force expressions with UO_Not to not be non-negative (PR #126846)
Yutong Zhu via cfe-commits
cfe-commits at lists.llvm.org
Thu May 15 14:18:22 PDT 2025
YutongZhuu wrote:
> > unsigned int foo(unsigned char x)
> > {
> > return ~(1<<x); // warning: implicit conversion loses integer precision: 'int' to 'unsigned int'
> > }
>
> Could you help me understand why clang is emitting the warning?
>
> Isn't it semantically equivalent to the following code?
>
> ```
> unsigned int foo(unsigned char x)
> {
> int i = ~(1<<x); // no -Wimplicit-int-conversion warning.
> return i; // no -Wimplicit-int-conversion warning.
> }
> ```
The conversion isn't implicit in the latter case.
https://github.com/llvm/llvm-project/pull/126846
More information about the cfe-commits
mailing list