2009-01-30 David Levin <levin@chromium.org>
authordglazkov@chromium.org <dglazkov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Jan 2009 22:02:04 +0000 (22:02 +0000)
committerdglazkov@chromium.org <dglazkov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Jan 2009 22:02:04 +0000 (22:02 +0000)
        Reviewed by Darin Adler.

        https://bugs.webkit.org/show_bug.cgi?id=23618
        Templated worker tasks should be more error proof to use.
        Fix Chromium build.

        * wtf/TypeTraits.h:
        (WTF::IsConvertibleToInteger::IsConvertibleToDouble):
        Avoid "possible loss of data" warning when using Microsoft's C++ compiler
        by avoiding an implicit conversion of int types to doubles.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@40418 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/wtf/TypeTraits.h

index 9fe3ca3cbf1a5c5fa314e7cc9634fa6cd6569c08..ce633c2a099563ff6caa3dc624ceb8b39b8b50c3 100644 (file)
@@ -1,3 +1,16 @@
+2009-01-30  David Levin  <levin@chromium.org>
+
+        Reviewed by Darin Adler.
+
+        https://bugs.webkit.org/show_bug.cgi?id=23618
+        Templated worker tasks should be more error proof to use.
+        Fix Chromium build.
+
+        * wtf/TypeTraits.h:
+        (WTF::IsConvertibleToInteger::IsConvertibleToDouble):
+        Avoid "possible loss of data" warning when using Microsoft's C++ compiler
+        by avoiding an implicit conversion of int types to doubles.
+
 2009-01-30  Laszlo Gombos  <laszlo.1.gombos@nokia.com>
 
         Reviewed by Simon Hausmann.
 2009-01-30  Laszlo Gombos  <laszlo.1.gombos@nokia.com>
 
         Reviewed by Simon Hausmann.
index c4ccf6fcf684e2e3c2bef71364e8781ae15c7f8b..6b7a975336bc98159c079da683eda5c290a91d64 100644 (file)
@@ -110,21 +110,34 @@ namespace WTF {
     COMPILE_ASSERT(IsPod<float>::value, WTF_IsPod_float_true);
     COMPILE_ASSERT(!IsPod<IsPod<bool> >::value, WTF_IsPod_struct_false);
 
     COMPILE_ASSERT(IsPod<float>::value, WTF_IsPod_float_true);
     COMPILE_ASSERT(!IsPod<IsPod<bool> >::value, WTF_IsPod_struct_false);
 
-    template<typename T> struct IsConvertibleToInteger {
-    private:
-        typedef char YesType;
-        struct NoType {
-            char padding[8];
+    template<typename T> class IsConvertibleToInteger {
+        // Avoid "possible loss of data" warning when using Microsoft's C++ compiler
+        // by not converting int's to doubles.
+        template<bool performCheck, typename U> class IsConvertibleToDouble;
+        template<typename U> class IsConvertibleToDouble<false, U> {
+        public:
+            static const bool value = false;
         };
 
         };
 
-        static YesType integerCheck(int);
-        static NoType integerCheck(...);
-        static T& t;
+        template<typename U> class IsConvertibleToDouble<true, U> {
+            typedef char YesType;
+            struct NoType {
+                char padding[8];
+            };
+
+            static YesType floatCheck(long double);
+            static NoType floatCheck(...);
+            static T& t;
+        public:
+            static const bool value = sizeof(floatCheck(t)) == sizeof(YesType);
+        };
 
     public:
 
     public:
-        static const bool value = sizeof(integerCheck(t)) == sizeof(YesType);
+        static const bool value = IsInteger<T>::value || IsConvertibleToDouble<!IsInteger<T>::value, T>::value;
     };
 
     };
 
+    enum IsConvertibleToIntegerCheck { };
+    COMPILE_ASSERT(IsConvertibleToInteger<IsConvertibleToIntegerCheck>::value, WTF_IsConvertibleToInteger_enum_true);
     COMPILE_ASSERT(IsConvertibleToInteger<bool>::value, WTF_IsConvertibleToInteger_bool_true);
     COMPILE_ASSERT(IsConvertibleToInteger<char>::value, WTF_IsConvertibleToInteger_char_true);
     COMPILE_ASSERT(IsConvertibleToInteger<signed char>::value, WTF_IsConvertibleToInteger_signed_char_true);
     COMPILE_ASSERT(IsConvertibleToInteger<bool>::value, WTF_IsConvertibleToInteger_bool_true);
     COMPILE_ASSERT(IsConvertibleToInteger<char>::value, WTF_IsConvertibleToInteger_char_true);
     COMPILE_ASSERT(IsConvertibleToInteger<signed char>::value, WTF_IsConvertibleToInteger_signed_char_true);