Bug 827521 - Work around spurious operator ambiguity errors in buggy versions of Clang. r=longsonr
authorGraeme McCutcheon <graememcc_firefox@graeme-online.co.uk>
Thu, 10 Jan 2013 14:37:30 +0000
changeset 118424 1ceb45fd14c5efcd464cd03a3f9d3b2edeb9fb02
parent 118423 2b3dd950e66fd82a168bea10eef09d611219d15b
child 118425 38667642253626d003cf1d8680f86412cf37a169
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerslongsonr
bugs827521
milestone21.0a1
Bug 827521 - Work around spurious operator ambiguity errors in buggy versions of Clang. r=longsonr
content/svg/content/src/SVGAnimatedPreserveAspectRatio.cpp
content/svg/content/src/SVGAnimatedPreserveAspectRatio.h
content/svg/content/src/SVGPreserveAspectRatio.h
--- a/content/svg/content/src/SVGAnimatedPreserveAspectRatio.cpp
+++ b/content/svg/content/src/SVGAnimatedPreserveAspectRatio.cpp
@@ -49,57 +49,56 @@ static nsSVGAttrTearoffTable<SVGAnimated
 static nsSVGAttrTearoffTable<SVGAnimatedPreserveAspectRatio, DOMSVGPreserveAspectRatio>
   sAnimSVGPAspectRatioTearoffTable;
 
 static uint16_t
 GetAlignForString(const nsAString &aAlignString)
 {
   for (uint32_t i = 0 ; i < ArrayLength(sAlignStrings) ; i++) {
     if (aAlignString.EqualsASCII(sAlignStrings[i])) {
-      return (i + SVG_PRESERVEASPECTRATIO_NONE);
+      return (i + SVG_ALIGN_MIN_VALID);
     }
   }
 
   return SVG_PRESERVEASPECTRATIO_UNKNOWN;
 }
 
 static void
 GetAlignString(nsAString& aAlignString, uint16_t aAlign)
 {
   NS_ASSERTION(
-    aAlign >= SVG_PRESERVEASPECTRATIO_NONE &&
-    aAlign <= SVG_PRESERVEASPECTRATIO_XMAXYMAX,
+    aAlign >= SVG_ALIGN_MIN_VALID && aAlign <= SVG_ALIGN_MAX_VALID,
     "Unknown align");
 
   aAlignString.AssignASCII(
-    sAlignStrings[aAlign - SVG_PRESERVEASPECTRATIO_NONE]);
+    sAlignStrings[aAlign - SVG_ALIGN_MIN_VALID]);
 }
 
 static uint16_t
 GetMeetOrSliceForString(const nsAString &aMeetOrSlice)
 {
   for (uint32_t i = 0 ; i < ArrayLength(sMeetOrSliceStrings) ; i++) {
     if (aMeetOrSlice.EqualsASCII(sMeetOrSliceStrings[i])) {
-      return (i + SVG_MEETORSLICE_MEET);
+      return (i + SVG_MEETORSLICE_MIN_VALID);
     }
   }
 
   return SVG_MEETORSLICE_UNKNOWN;
 }
 
 static void
 GetMeetOrSliceString(nsAString& aMeetOrSliceString, uint16_t aMeetOrSlice)
 {
   NS_ASSERTION(
-    aMeetOrSlice >= SVG_MEETORSLICE_MEET &&
-    aMeetOrSlice <= SVG_MEETORSLICE_SLICE,
+    aMeetOrSlice >= SVG_MEETORSLICE_MIN_VALID &&
+    aMeetOrSlice <= SVG_MEETORSLICE_MAX_VALID,
     "Unknown meetOrSlice");
 
   aMeetOrSliceString.AssignASCII(
-    sMeetOrSliceStrings[aMeetOrSlice - SVG_MEETORSLICE_MEET]);
+    sMeetOrSliceStrings[aMeetOrSlice - SVG_MEETORSLICE_MIN_VALID]);
 }
 
 already_AddRefed<DOMSVGPreserveAspectRatio>
 DOMSVGAnimatedPreserveAspectRatio::BaseVal()
 {
   nsRefPtr<DOMSVGPreserveAspectRatio> domBaseVal =
     sBaseSVGPAspectRatioTearoffTable.GetTearoff(mVal);
   if (!domBaseVal) {
@@ -221,17 +220,17 @@ SVGAnimatedPreserveAspectRatio::GetBaseV
 
   if (mBaseVal.mDefer) {
     aValueAsString.AppendLiteral("defer ");
   }
 
   GetAlignString(tmpString, mBaseVal.mAlign);
   aValueAsString.Append(tmpString);
 
-  if (mBaseVal.mAlign != SVG_PRESERVEASPECTRATIO_NONE) {
+  if (mBaseVal.mAlign != uint8_t(SVG_PRESERVEASPECTRATIO_NONE)) {
 
     aValueAsString.AppendLiteral(" ");
     GetMeetOrSliceString(tmpString, mBaseVal.mMeetOrSlice);
     aValueAsString.Append(tmpString);
   }
 }
 
 void
--- a/content/svg/content/src/SVGAnimatedPreserveAspectRatio.h
+++ b/content/svg/content/src/SVGAnimatedPreserveAspectRatio.h
@@ -37,29 +37,28 @@ public:
   nsresult SetBaseValueString(const nsAString& aValue,
                               nsSVGElement *aSVGElement,
                               bool aDoSetAttr);
   void GetBaseValueString(nsAString& aValue) const;
 
   void SetBaseValue(const SVGPreserveAspectRatio &aValue,
                     nsSVGElement *aSVGElement);
   nsresult SetBaseAlign(uint16_t aAlign, nsSVGElement *aSVGElement) {
-    if (aAlign < SVG_PRESERVEASPECTRATIO_NONE ||
-        aAlign > SVG_PRESERVEASPECTRATIO_XMAXYMAX) {
+    if (aAlign < SVG_ALIGN_MIN_VALID || aAlign > SVG_ALIGN_MAX_VALID) {
       return NS_ERROR_FAILURE;
     }
     SetBaseValue(SVGPreserveAspectRatio(
                    static_cast<SVGAlign>(aAlign), mBaseVal.GetMeetOrSlice(),
                    mBaseVal.GetDefer()),
                  aSVGElement);
     return NS_OK;
   }
   nsresult SetBaseMeetOrSlice(uint16_t aMeetOrSlice, nsSVGElement *aSVGElement) {
-    if (aMeetOrSlice < SVG_MEETORSLICE_MEET ||
-        aMeetOrSlice > SVG_MEETORSLICE_SLICE) {
+    if (aMeetOrSlice < SVG_MEETORSLICE_MIN_VALID ||
+        aMeetOrSlice > SVG_MEETORSLICE_MAX_VALID) {
       return NS_ERROR_FAILURE;
     }
     SetBaseValue(SVGPreserveAspectRatio(
                    mBaseVal.GetAlign(), static_cast<SVGMeetOrSlice>(aMeetOrSlice),
                    mBaseVal.GetDefer()),
                  aSVGElement);
     return NS_OK;
   }
--- a/content/svg/content/src/SVGPreserveAspectRatio.h
+++ b/content/svg/content/src/SVGPreserveAspectRatio.h
@@ -23,23 +23,33 @@ enum SVGAlign MOZ_ENUM_TYPE(uint8_t) {
   SVG_PRESERVEASPECTRATIO_XMINYMID = 5,
   SVG_PRESERVEASPECTRATIO_XMIDYMID = 6,
   SVG_PRESERVEASPECTRATIO_XMAXYMID = 7,
   SVG_PRESERVEASPECTRATIO_XMINYMAX = 8,
   SVG_PRESERVEASPECTRATIO_XMIDYMAX = 9,
   SVG_PRESERVEASPECTRATIO_XMAXYMAX = 10
 };
 
+// These constants represent the range of valid enum values for the <align>
+// parameter. They exclude the sentinel _UNKNOWN value.
+const uint16_t SVG_ALIGN_MIN_VALID = SVG_PRESERVEASPECTRATIO_NONE;
+const uint16_t SVG_ALIGN_MAX_VALID = SVG_PRESERVEASPECTRATIO_XMAXYMAX;
+
 // Meet-or-slice Types
 enum SVGMeetOrSlice MOZ_ENUM_TYPE(uint8_t) {
   SVG_MEETORSLICE_UNKNOWN = 0,
   SVG_MEETORSLICE_MEET = 1,
   SVG_MEETORSLICE_SLICE = 2
 };
 
+// These constants represent the range of valid enum values for the
+// <meetOrSlice> parameter. They exclude the sentinel _UNKNOWN value.
+const uint16_t SVG_MEETORSLICE_MIN_VALID = SVG_MEETORSLICE_MEET;
+const uint16_t SVG_MEETORSLICE_MAX_VALID = SVG_MEETORSLICE_SLICE;
+
 class SVGAnimatedPreserveAspectRatio;
 
 class SVGPreserveAspectRatio MOZ_FINAL
 {
   friend class SVGAnimatedPreserveAspectRatio;
 public:
   SVGPreserveAspectRatio(SVGAlign aAlign, SVGMeetOrSlice aMeetOrSlice,
                          bool aDefer = false)
@@ -52,30 +62,29 @@ public:
 
   explicit SVGPreserveAspectRatio()
     : mAlign(SVG_PRESERVEASPECTRATIO_UNKNOWN)
     , mMeetOrSlice(SVG_MEETORSLICE_UNKNOWN)
     , mDefer(false)
   {}
 
   nsresult SetAlign(uint16_t aAlign) {
-    if (aAlign < SVG_PRESERVEASPECTRATIO_NONE ||
-        aAlign > SVG_PRESERVEASPECTRATIO_XMAXYMAX)
+    if (aAlign < SVG_ALIGN_MIN_VALID || aAlign > SVG_ALIGN_MAX_VALID)
       return NS_ERROR_FAILURE;
     mAlign = static_cast<uint8_t>(aAlign);
     return NS_OK;
   }
 
   SVGAlign GetAlign() const {
     return static_cast<SVGAlign>(mAlign);
   }
 
   nsresult SetMeetOrSlice(uint16_t aMeetOrSlice) {
-    if (aMeetOrSlice < SVG_MEETORSLICE_MEET ||
-        aMeetOrSlice > SVG_MEETORSLICE_SLICE)
+    if (aMeetOrSlice < SVG_MEETORSLICE_MIN_VALID ||
+        aMeetOrSlice > SVG_MEETORSLICE_MAX_VALID)
       return NS_ERROR_FAILURE;
     mMeetOrSlice = static_cast<uint8_t>(aMeetOrSlice);
     return NS_OK;
   }
 
   SVGMeetOrSlice GetMeetOrSlice() const {
     return static_cast<SVGMeetOrSlice>(mMeetOrSlice);
   }