[PATCH] D21870: [libcxx] [test] Avoid applying unary minus to unsigned integers.

Stephan T. Lavavej via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 29 16:20:25 PDT 2016


STL_MSFT created this revision.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.

Avoid applying unary minus to unsigned integers.

This is confusing because first you have to remember what unsigned negation does, then you have to worry about the usual arithmetic conversions during the comparison. It's simpler to express the most negative values as "blah - 1" expressions, and then the only UAC involved is widening int to long long and that's easy.

Fixes MSVC warning/error C4146 "unary minus operator applied to unsigned type, result still unsigned".

http://reviews.llvm.org/D21870

Files:
  test/std/depr/depr.c.headers/stdint_h.pass.cpp
  test/std/language.support/cstdint/cstdint.syn/cstdint.pass.cpp

Index: test/std/language.support/cstdint/cstdint.syn/cstdint.pass.cpp
===================================================================
--- test/std/language.support/cstdint/cstdint.syn/cstdint.pass.cpp
+++ test/std/language.support/cstdint/cstdint.syn/cstdint.pass.cpp
@@ -172,8 +172,8 @@
     // INTN_MIN
     static_assert(INT8_MIN == -128, "INT8_MIN == -128");
     static_assert(INT16_MIN == -32768, "INT16_MIN == -32768");
-    static_assert(INT32_MIN == -2147483648U, "INT32_MIN == -2147483648");
-    static_assert(INT64_MIN == -9223372036854775808ULL, "INT64_MIN == -9223372036854775808LL");
+    static_assert(INT32_MIN == -2147483647 - 1, "INT32_MIN == -2147483648");
+    static_assert(INT64_MIN == -9223372036854775807LL - 1, "INT64_MIN == -9223372036854775808LL");
 
     // INTN_MAX
     static_assert(INT8_MAX == 127, "INT8_MAX == 127");
@@ -190,8 +190,8 @@
     // INT_FASTN_MIN
     static_assert(INT_FAST8_MIN <= -128, "INT_FAST8_MIN <= -128");
     static_assert(INT_FAST16_MIN <= -32768, "INT_FAST16_MIN <= -32768");
-    static_assert(INT_FAST32_MIN <= -2147483648U, "INT_FAST32_MIN <= -2147483648");
-    static_assert(INT_FAST64_MIN <= -9223372036854775808ULL, "INT_FAST64_MIN <= -9223372036854775808LL");
+    static_assert(INT_FAST32_MIN <= -2147483647 - 1, "INT_FAST32_MIN <= -2147483648");
+    static_assert(INT_FAST64_MIN <= -9223372036854775807LL - 1, "INT_FAST64_MIN <= -9223372036854775808LL");
 
     // INT_FASTN_MAX
     static_assert(INT_FAST8_MAX >= 127, "INT_FAST8_MAX >= 127");
Index: test/std/depr/depr.c.headers/stdint_h.pass.cpp
===================================================================
--- test/std/depr/depr.c.headers/stdint_h.pass.cpp
+++ test/std/depr/depr.c.headers/stdint_h.pass.cpp
@@ -171,8 +171,8 @@
     // INTN_MIN
     static_assert(INT8_MIN == -128, "INT8_MIN == -128");
     static_assert(INT16_MIN == -32768, "INT16_MIN == -32768");
-    static_assert(INT32_MIN == -2147483648U, "INT32_MIN == -2147483648");
-    static_assert(INT64_MIN == -9223372036854775808ULL, "INT64_MIN == -9223372036854775808LL");
+    static_assert(INT32_MIN == -2147483647 - 1, "INT32_MIN == -2147483648");
+    static_assert(INT64_MIN == -9223372036854775807LL - 1, "INT64_MIN == -9223372036854775808LL");
 
     // INTN_MAX
     static_assert(INT8_MAX == 127, "INT8_MAX == 127");
@@ -189,8 +189,8 @@
     // INT_FASTN_MIN
     static_assert(INT_FAST8_MIN <= -128, "INT_FAST8_MIN <= -128");
     static_assert(INT_FAST16_MIN <= -32768, "INT_FAST16_MIN <= -32768");
-    static_assert(INT_FAST32_MIN <= -2147483648U, "INT_FAST32_MIN <= -2147483648");
-    static_assert(INT_FAST64_MIN <= -9223372036854775808ULL, "INT_FAST64_MIN <= -9223372036854775808LL");
+    static_assert(INT_FAST32_MIN <= -2147483647 - 1, "INT_FAST32_MIN <= -2147483648");
+    static_assert(INT_FAST64_MIN <= -9223372036854775807LL - 1, "INT_FAST64_MIN <= -9223372036854775808LL");
 
     // INT_FASTN_MAX
     static_assert(INT_FAST8_MAX >= 127, "INT_FAST8_MAX >= 127");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21870.62302.patch
Type: text/x-patch
Size: 2992 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160629/329d1643/attachment.bin>


More information about the cfe-commits mailing list