[PATCH] D22472: Write isUInt using template specializations to work around an incorrect MSVC warning.

Justin Lebar via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 18 13:48:05 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL275909: Write isUInt using template specializations to work around an incorrect MSVC… (authored by jlebar).

Changed prior to commit:
  https://reviews.llvm.org/D22472?vs=64370&id=64377#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D22472

Files:
  llvm/trunk/include/llvm/Support/MathExtras.h

Index: llvm/trunk/include/llvm/Support/MathExtras.h
===================================================================
--- llvm/trunk/include/llvm/Support/MathExtras.h
+++ llvm/trunk/include/llvm/Support/MathExtras.h
@@ -290,10 +290,21 @@
 }
 
 /// isUInt - Checks if an unsigned integer fits into the given bit width.
-template<unsigned N>
-inline bool isUInt(uint64_t x) {
-  static_assert(N > 0, "isUInt<0> doesn't make sense.");
-  return N >= 64 || x < (UINT64_C(1)<<(N));
+///
+/// This is written as two functions rather than as simply
+///
+///   return N >= 64 || X < (UINT64_C(1) << N);
+///
+/// to keep MSVC from (incorrectly) warning on isUInt<64> that we're shifting
+/// left too many places.
+template <unsigned N>
+inline typename std::enable_if<(N < 64), bool>::type isUInt(uint64_t X) {
+  static_assert(N > 0, "isUInt<0> doesn't make sense");
+  return X < (UINT64_C(1) << N);
+}
+template <unsigned N>
+inline typename std::enable_if<N >= 64, bool>::type isUInt(uint64_t X) {
+  return true;
 }
 
 // Template specializations to get better code for common cases.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22472.64377.patch
Type: text/x-patch
Size: 1085 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160718/d9477122/attachment.bin>


More information about the llvm-commits mailing list