[llvm] r219065 - Solve Visual C++ warning C4805 on getAsInteger<bool>.

Yaron Keren yaron.keren at gmail.com
Sat Oct 4 12:58:30 PDT 2014


Author: yrnkrn
Date: Sat Oct  4 14:58:30 2014
New Revision: 219065

URL: http://llvm.org/viewvc/llvm-project?rev=219065&view=rev
Log:
Solve Visual C++ warning C4805 on getAsInteger<bool>.

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)


Modified:
    llvm/trunk/include/llvm/ADT/StringRef.h

Modified: llvm/trunk/include/llvm/ADT/StringRef.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringRef.h?rev=219065&r1=219064&r2=219065&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/StringRef.h (original)
+++ llvm/trunk/include/llvm/ADT/StringRef.h Sat Oct  4 14:58:30 2014
@@ -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;





More information about the llvm-commits mailing list