Title: [288181] trunk/Source/WebCore
Revision
288181
Author
wei...@apple.com
Date
2022-01-18 21:15:25 -0800 (Tue, 18 Jan 2022)

Log Message

ColorTypes are no longer constexpr in debug builds due to std::isnan() in range assertion
https://bugs.webkit.org/show_bug.cgi?id=235346

Unreviewed build fix.

Replace std::isnan() in color type range assertions with a constexpr variant using the x != x
construction for detection.


* platform/graphics/ColorTypes.h:
(WebCore::constexprIsNaN):
(WebCore::assertInRange):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (288180 => 288181)


--- trunk/Source/WebCore/ChangeLog	2022-01-19 05:13:37 UTC (rev 288180)
+++ trunk/Source/WebCore/ChangeLog	2022-01-19 05:15:25 UTC (rev 288181)
@@ -1,3 +1,17 @@
+2022-01-18  Sam Weinig  <wei...@apple.com>
+
+        ColorTypes are no longer constexpr in debug builds due to std::isnan() in range assertion
+        https://bugs.webkit.org/show_bug.cgi?id=235346
+
+        Unreviewed build fix.
+
+        Replace std::isnan() in color type range assertions with a constexpr variant using the x != x
+        construction for detection.
+
+        * platform/graphics/ColorTypes.h:
+        (WebCore::constexprIsNaN):
+        (WebCore::assertInRange):
+
 2022-01-18  Megan Gardner  <megan_gard...@apple.com>
 
         Loupe sometimes flips to the bottom of the page when dragging the end of a selection to the top of a page with selection flipping.

Modified: trunk/Source/WebCore/platform/graphics/ColorTypes.h (288180 => 288181)


--- trunk/Source/WebCore/platform/graphics/ColorTypes.h	2022-01-19 05:13:37 UTC (rev 288180)
+++ trunk/Source/WebCore/platform/graphics/ColorTypes.h	2022-01-19 05:15:25 UTC (rev 288181)
@@ -132,17 +132,24 @@
 
 #if ASSERT_ENABLED
 
+template<typename ComponentType>
+constexpr bool constexprIsNaN(ComponentType value)
+{
+    // FIXME: Replace std::isnan() once std::isnan() is constexpr.
+    return value != value;
+}
+
 template<typename ColorType, typename std::enable_if_t<std::is_same_v<typename ColorType::ComponentType, float>>* = nullptr>
 constexpr void assertInRange(ColorType color)
 {
     auto components = asColorComponents(color.unresolved());
     for (unsigned i = 0; i < 3; ++i) {
-        if (std::isnan(components[i]))
+        if (constexprIsNaN(components[i]))
             continue;
         ASSERT_WITH_MESSAGE(components[i] >= ColorType::Model::componentInfo[i].min, "Component at index %d is %f and is less than the allowed minimum %f", i,  components[i], ColorType::Model::componentInfo[i].min);
         ASSERT_WITH_MESSAGE(components[i] <= ColorType::Model::componentInfo[i].max, "Component at index %d is %f and is greater than the allowed maximum %f", i,  components[i], ColorType::Model::componentInfo[i].max);
     }
-    if (!std::isnan(components[3])) {
+    if (constexprIsNaN(components[3])) {
         ASSERT_WITH_MESSAGE(components[3] >= AlphaTraits<typename ColorType::ComponentType>::transparent, "Alpha is %f and is less than the allowed minimum (transparent) %f", components[3], AlphaTraits<typename ColorType::ComponentType>::transparent);
         ASSERT_WITH_MESSAGE(components[3] <= AlphaTraits<typename ColorType::ComponentType>::opaque, "Alpha is %f and is greater than the allowed maximum (opaque) %f", components[3], AlphaTraits<typename ColorType::ComponentType>::opaque);
     }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to