[PATCH] D52137: Added warning for unary minus used with unsigned type

Roman Lebedev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 15 11:16:57 PDT 2018


lebedev.ri added a comment.

I don't think this makes much sense.

In https://reviews.llvm.org/D52137#1236011, @xbolva00 wrote:

> /home/xbolva00/LLVM/build/lib/clang/8.0.0/include/bmiintrin.h:312:16: error: unary minus operator applied to type 'unsigned long long', result value is still unsigned
>
>   return __X & -__X;
>   
>
> @RKSimon what do you think? valid?


https://godbolt.org/z/2n3lQp <- i'm not sure why the second one is better, how how the first one is broken.



================
Comment at: lib/Sema/SemaExpr.cpp:12651
+      if (Opc == UO_Minus && resultType->isUnsignedIntegerType())
+        return ExprError(Diag(OpLoc, diag::err_unsignedtypecheck_unary_minus)
+                         << resultType << Input.get()->getSourceRange());
----------------
Why is this an error?


https://reviews.llvm.org/D52137





More information about the cfe-commits mailing list