trick the compiler into not knowning that I will generate an overflow
authorreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 3 May 2013 16:30:44 +0000 (16:30 +0000)
committerreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 3 May 2013 16:30:44 +0000 (16:30 +0000)
(which is the point of the test). This avoids a warning, which breaks
our bots.

git-svn-id: http://skia.googlecode.com/svn/trunk@8991 2bbb7eff-a529-9590-31e7-b0007b416f81

tests/PointTest.cpp

index 9d4bdfd..b909762 100644 (file)
@@ -50,10 +50,22 @@ static void test_length(skiatest::Reporter* reporter, SkScalar x, SkScalar y,
     test_Normalize(reporter, x, y);
 }
 
+// Ugh. Windows compiler can dive into other .cpp files, and sometimes
+// notices that I will generate an overflow... which is exactly the point
+// of this test!
+//
+// To avoid this warning, I need to convince the compiler that I might not
+// use that big value, hence this hacky helper function: reporter is
+// ALWAYS non-null. (shhhhhh, don't tell the compiler that).
+template <typename T> T get_value(skiatest::Reporter* reporter, T value) {
+    return reporter ? value : 0;
+}
+
 // test that we handle very large values correctly. i.e. that we can
 // successfully normalize something whose mag overflows a float.
 static void test_overflow(skiatest::Reporter* reporter) {
-    SkPoint pt = { SkFloatToScalar(3.4e38f), SkFloatToScalar(3.4e38f) };
+    SkScalar bigFloat = get_value(reporter, SkFloatToScalar(3.4e38f));
+    SkPoint pt = { bigFloat, bigFloat };
     
     SkScalar length = pt.length();
     REPORTER_ASSERT(reporter, !SkScalarIsFinite(length));