Solve Visual C++ warning C4805 on getAsInteger<bool>.
authorYaron Keren <yaron.keren@gmail.com>
Sat, 4 Oct 2014 19:58:30 +0000 (19:58 +0000)
committerYaron Keren <yaron.keren@gmail.com>
Sat, 4 Oct 2014 19:58:30 +0000 (19:58 +0000)
Fix http://llvm.org/PR21158 by adding a cast to unsigned long long,
so the comparison would be between two unsigned long longs instead
of bool and unsigned long long.

      if (getAsUnsignedInteger(*this, Radix, ULLVal) ||
          static_cast<unsigned long long>(static_cast<T>(ULLVal)) != ULLVal)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219065 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/StringRef.h

index f1861c8f92bce2351a166de176b5bdf55c6d3647..778fa10a32c252e7e5bd22bad634ce1dddb804c7 100644 (file)
@@ -347,8 +347,11 @@ namespace llvm {
     typename std::enable_if<!std::numeric_limits<T>::is_signed, bool>::type
     getAsInteger(unsigned Radix, T &Result) const {
       unsigned long long ULLVal;
+      // The additional cast to unsigned long long is required to avoid the
+      // Visual C++ warning C4805: '!=' : unsafe mix of type 'bool' and type
+      // 'unsigned __int64' when instantiating getAsInteger with T = bool.
       if (getAsUnsignedInteger(*this, Radix, ULLVal) ||
-            static_cast<T>(ULLVal) != ULLVal)
+          static_cast<unsigned long long>(static_cast<T>(ULLVal)) != ULLVal)
         return true;
       Result = ULLVal;
       return false;