Bug 1147706 - Warn if we don't use the result of const methods on BaseRect and its subclasses. r=tn
authorSeth Fowler <seth@mozilla.com>
Thu, 26 Mar 2015 15:39:47 -0700
changeset 266358 1cf1e2b49d90e16a631751d24e10563096de588d
parent 266357 c035d63ade9d23b29b357656a6c6d6e3785315ec
child 266359 950e7c72280af30c10ed9298b844f76cf4920cc4
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstn
bugs1147706
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1147706 - Warn if we don't use the result of const methods on BaseRect and its subclasses. r=tn
gfx/2d/BaseRect.h
gfx/src/nsRect.h
--- a/gfx/2d/BaseRect.h
+++ b/gfx/2d/BaseRect.h
@@ -101,17 +101,17 @@ struct BaseRect {
     return !IsEmpty() && !aRect.IsEmpty() &&
            x < aRect.XMost() && aRect.x < XMost() &&
            y < aRect.YMost() && aRect.y < YMost();
   }
   // Returns the rectangle containing the intersection of the points
   // (including edges) of *this and aRect. If there are no points in that
   // intersection, returns an empty rectangle with x/y set to the std::max of the x/y
   // of *this and aRect.
-  Sub Intersect(const Sub& aRect) const
+  MOZ_WARN_UNUSED_RESULT Sub Intersect(const Sub& aRect) const
   {
     Sub result;
     result.x = std::max<T>(x, aRect.x);
     result.y = std::max<T>(y, aRect.y);
     result.width = std::min<T>(x - result.x + width, aRect.x - result.x + aRect.width);
     result.height = std::min<T>(y - result.y + height, aRect.y - result.y + aRect.height);
     if (result.width < 0 || result.height < 0) {
       result.SizeTo(0, 0);
@@ -129,30 +129,30 @@ struct BaseRect {
     *static_cast<Sub*>(this) = aRect1.Intersect(aRect2);
     return !IsEmpty();
   }
 
   // Returns the smallest rectangle that contains both the area of both
   // this and aRect2.
   // Thus, empty input rectangles are ignored.
   // If both rectangles are empty, returns this.
-  Sub Union(const Sub& aRect) const
+  MOZ_WARN_UNUSED_RESULT Sub Union(const Sub& aRect) const
   {
     if (IsEmpty()) {
       return aRect;
     } else if (aRect.IsEmpty()) {
       return *static_cast<const Sub*>(this);
     } else {
       return UnionEdges(aRect);
     }
   }
   // Returns the smallest rectangle that contains both the points (including
   // edges) of both aRect1 and aRect2.
   // Thus, empty input rectangles are allowed to affect the result.
-  Sub UnionEdges(const Sub& aRect) const
+  MOZ_WARN_UNUSED_RESULT Sub UnionEdges(const Sub& aRect) const
   {
     Sub result;
     result.x = std::min(x, aRect.x);
     result.y = std::min(y, aRect.y);
     result.width = std::max(XMost(), aRect.XMost()) - result.x;
     result.height = std::max(YMost(), aRect.YMost()) - result.y;
     return result;
   }
@@ -520,28 +520,28 @@ struct BaseRect {
     width = std::max<T>(0, right - x);
     height = std::max<T>(0, bottom - y);
   }
 
   /**
    * Clamp aPoint to this rectangle. It is allowed to end up on any
    * edge of the rectangle.
    */
-  Point ClampPoint(const Point& aPoint) const
+  MOZ_WARN_UNUSED_RESULT Point ClampPoint(const Point& aPoint) const
   {
     return Point(std::max(x, std::min(XMost(), aPoint.x)),
                  std::max(y, std::min(YMost(), aPoint.y)));
   }
 
   /**
    * Clamp this rectangle to be inside aRect. The function returns a copy of
    * this rect after it is forced inside the bounds of aRect. It will attempt to
    * retain the size but will shrink the dimensions that don't fit.
    */
-  Sub ForceInside(const Sub& aRect) const
+  MOZ_WARN_UNUSED_RESULT Sub ForceInside(const Sub& aRect) const
   {
     Sub rect(std::max(aRect.x, x),
              std::max(aRect.y, y),
              std::min(aRect.width, width),
              std::min(aRect.height, height));
     rect.x = std::min(rect.XMost(), aRect.XMost()) - rect.width;
     rect.y = std::min(rect.YMost(), aRect.YMost()) - rect.height;
     return rect;
--- a/gfx/src/nsRect.h
+++ b/gfx/src/nsRect.h
@@ -54,28 +54,28 @@ struct NS_GFX nsRect :
     MOZ_COUNT_DTOR(nsRect);
   }
 #endif
 
   // We have saturating versions of all the Union methods. These avoid
   // overflowing nscoord values in the 'width' and 'height' fields by
   // clamping the width and height values to nscoord_MAX if necessary.
 
-  nsRect SaturatingUnion(const nsRect& aRect) const
+  MOZ_WARN_UNUSED_RESULT nsRect SaturatingUnion(const nsRect& aRect) const
   {
     if (IsEmpty()) {
       return aRect;
     } else if (aRect.IsEmpty()) {
       return *static_cast<const nsRect*>(this);
     } else {
       return SaturatingUnionEdges(aRect);
     }
   }
 
-  nsRect SaturatingUnionEdges(const nsRect& aRect) const
+  MOZ_WARN_UNUSED_RESULT nsRect SaturatingUnionEdges(const nsRect& aRect) const
   {
 #ifdef NS_COORD_IS_FLOAT
     return UnionEdges(aRect);
 #else
     nsRect result;
     result.x = std::min(aRect.x, x);
     int64_t w = std::max(int64_t(aRect.x) + aRect.width, int64_t(x) + width) - result.x;
     if (MOZ_UNLIKELY(w > nscoord_MAX)) {
@@ -102,25 +102,25 @@ struct NS_GFX nsRect :
     }
     result.height = nscoord(h);
     return result;
 #endif
   }
 
 #ifndef NS_COORD_IS_FLOAT
   // Make all nsRect Union methods be saturating.
-  nsRect UnionEdges(const nsRect& aRect) const
+  MOZ_WARN_UNUSED_RESULT nsRect UnionEdges(const nsRect& aRect) const
   {
     return SaturatingUnionEdges(aRect);
   }
   void UnionRectEdges(const nsRect& aRect1, const nsRect& aRect2)
   {
     *this = aRect1.UnionEdges(aRect2);
   }
-  nsRect Union(const nsRect& aRect) const
+  MOZ_WARN_UNUSED_RESULT nsRect Union(const nsRect& aRect) const
   {
     return SaturatingUnion(aRect);
   }
   void UnionRect(const nsRect& aRect1, const nsRect& aRect2)
   {
     *this = aRect1.Union(aRect2);
   }
 #endif
@@ -143,27 +143,38 @@ struct NS_GFX nsRect :
    * @param aToAPP the APP to scale to
    * @note this can turn an empty rectangle into a non-empty rectangle
    */
   MOZ_WARN_UNUSED_RESULT inline nsRect
     ScaleToOtherAppUnitsRoundOut(int32_t aFromAPP, int32_t aToAPP) const;
   MOZ_WARN_UNUSED_RESULT inline nsRect
     ScaleToOtherAppUnitsRoundIn(int32_t aFromAPP, int32_t aToAPP) const;
 
-  inline nsIntRect ScaleToNearestPixels(float aXScale, float aYScale,
-                                        nscoord aAppUnitsPerPixel) const;
-  inline nsIntRect ToNearestPixels(nscoord aAppUnitsPerPixel) const;
+  MOZ_WARN_UNUSED_RESULT inline nsIntRect
+  ScaleToNearestPixels(float aXScale, float aYScale,
+                       nscoord aAppUnitsPerPixel) const;
+
+  MOZ_WARN_UNUSED_RESULT inline nsIntRect
+  ToNearestPixels(nscoord aAppUnitsPerPixel) const;
+
   // Note: this can turn an empty rectangle into a non-empty rectangle
-  inline nsIntRect ScaleToOutsidePixels(float aXScale, float aYScale,
-                                        nscoord aAppUnitsPerPixel) const;
+  MOZ_WARN_UNUSED_RESULT inline nsIntRect
+  ScaleToOutsidePixels(float aXScale, float aYScale,
+                       nscoord aAppUnitsPerPixel) const;
+
   // Note: this can turn an empty rectangle into a non-empty rectangle
-  inline nsIntRect ToOutsidePixels(nscoord aAppUnitsPerPixel) const;
-  inline nsIntRect ScaleToInsidePixels(float aXScale, float aYScale,
-                                       nscoord aAppUnitsPerPixel) const;
-  inline nsIntRect ToInsidePixels(nscoord aAppUnitsPerPixel) const;
+  MOZ_WARN_UNUSED_RESULT inline nsIntRect
+  ToOutsidePixels(nscoord aAppUnitsPerPixel) const;
+
+  MOZ_WARN_UNUSED_RESULT inline nsIntRect
+  ScaleToInsidePixels(float aXScale, float aYScale,
+                      nscoord aAppUnitsPerPixel) const;
+
+  MOZ_WARN_UNUSED_RESULT inline nsIntRect
+  ToInsidePixels(nscoord aAppUnitsPerPixel) const;
 
   // This is here only to keep IPDL-generated code happy. DO NOT USE.
   bool operator==(const nsRect& aRect) const
   {
     return IsEqualEdges(aRect);
   }
 };
 
@@ -181,17 +192,18 @@ struct NS_GFX nsIntRect :
   nsIntRect(const nsIntPoint& aOrigin, const nsIntSize &aSize) : Super(aOrigin, aSize)
   {
   }
   nsIntRect(int32_t aX, int32_t aY, int32_t aWidth, int32_t aHeight) :
       Super(aX, aY, aWidth, aHeight)
   {
   }
 
-  inline nsRect ToAppUnits(nscoord aAppUnitsPerPixel) const;
+  MOZ_WARN_UNUSED_RESULT inline nsRect
+  ToAppUnits(nscoord aAppUnitsPerPixel) const;
 
   // Returns a special nsIntRect that's used in some places to signify
   // "all available space".
   static const nsIntRect& GetMaxSizedIntRect() {
     static const nsIntRect r(0, 0, INT32_MAX, INT32_MAX);
     return r;
   }