Run `git cl format --full` on safe_conversions_impl.h
It had a large-ish number of non-standard-formatted lines. This caused
a problem in another CL where I try to move this file: `git cl format`
wants to reformat all these lines, which in turn causes the rename
detection to treat it as a delete+add, making reviewing hard.
Better to just reformat it in a separate CL and get it over with.
BUG=none
Change-Id: I619f0454546e8a55fba58da08073da9bb1d06207
Reviewed-on: https://webrtc-review.googlesource.com/20865
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20582}
diff --git a/rtc_base/safe_conversions_impl.h b/rtc_base/safe_conversions_impl.h
index f9f6256..7f05a11 100644
--- a/rtc_base/safe_conversions_impl.h
+++ b/rtc_base/safe_conversions_impl.h
@@ -18,29 +18,21 @@
namespace rtc {
namespace internal {
-enum DstSign {
- DST_UNSIGNED,
- DST_SIGNED
-};
+enum DstSign { DST_UNSIGNED, DST_SIGNED };
-enum SrcSign {
- SRC_UNSIGNED,
- SRC_SIGNED
-};
+enum SrcSign { SRC_UNSIGNED, SRC_SIGNED };
-enum DstRange {
- OVERLAPS_RANGE,
- CONTAINS_RANGE
-};
+enum DstRange { OVERLAPS_RANGE, CONTAINS_RANGE };
// Helper templates to statically determine if our destination type can contain
// all values represented by the source type.
-template <typename Dst, typename Src,
- DstSign IsDstSigned = std::numeric_limits<Dst>::is_signed ?
- DST_SIGNED : DST_UNSIGNED,
- SrcSign IsSrcSigned = std::numeric_limits<Src>::is_signed ?
- SRC_SIGNED : SRC_UNSIGNED>
+template <typename Dst,
+ typename Src,
+ DstSign IsDstSigned =
+ std::numeric_limits<Dst>::is_signed ? DST_SIGNED : DST_UNSIGNED,
+ SrcSign IsSrcSigned =
+ std::numeric_limits<Src>::is_signed ? SRC_SIGNED : SRC_UNSIGNED>
struct StaticRangeCheck {};
template <typename Dst, typename Src>
@@ -48,20 +40,18 @@
typedef std::numeric_limits<Dst> DstLimits;
typedef std::numeric_limits<Src> SrcLimits;
// Compare based on max_exponent, which we must compute for integrals.
- static const size_t kDstMaxExponent = DstLimits::is_iec559 ?
- DstLimits::max_exponent :
- (sizeof(Dst) * 8 - 1);
- static const size_t kSrcMaxExponent = SrcLimits::is_iec559 ?
- SrcLimits::max_exponent :
- (sizeof(Src) * 8 - 1);
- static const DstRange value = kDstMaxExponent >= kSrcMaxExponent ?
- CONTAINS_RANGE : OVERLAPS_RANGE;
+ static const size_t kDstMaxExponent =
+ DstLimits::is_iec559 ? DstLimits::max_exponent : (sizeof(Dst) * 8 - 1);
+ static const size_t kSrcMaxExponent =
+ SrcLimits::is_iec559 ? SrcLimits::max_exponent : (sizeof(Src) * 8 - 1);
+ static const DstRange value =
+ kDstMaxExponent >= kSrcMaxExponent ? CONTAINS_RANGE : OVERLAPS_RANGE;
};
template <typename Dst, typename Src>
struct StaticRangeCheck<Dst, Src, DST_UNSIGNED, SRC_UNSIGNED> {
- static const DstRange value = sizeof(Dst) >= sizeof(Src) ?
- CONTAINS_RANGE : OVERLAPS_RANGE;
+ static const DstRange value =
+ sizeof(Dst) >= sizeof(Src) ? CONTAINS_RANGE : OVERLAPS_RANGE;
};
template <typename Dst, typename Src>
@@ -69,12 +59,11 @@
typedef std::numeric_limits<Dst> DstLimits;
typedef std::numeric_limits<Src> SrcLimits;
// Compare based on max_exponent, which we must compute for integrals.
- static const size_t kDstMaxExponent = DstLimits::is_iec559 ?
- DstLimits::max_exponent :
- (sizeof(Dst) * 8 - 1);
+ static const size_t kDstMaxExponent =
+ DstLimits::is_iec559 ? DstLimits::max_exponent : (sizeof(Dst) * 8 - 1);
static const size_t kSrcMaxExponent = sizeof(Src) * 8;
- static const DstRange value = kDstMaxExponent >= kSrcMaxExponent ?
- CONTAINS_RANGE : OVERLAPS_RANGE;
+ static const DstRange value =
+ kDstMaxExponent >= kSrcMaxExponent ? CONTAINS_RANGE : OVERLAPS_RANGE;
};
template <typename Dst, typename Src>
@@ -82,7 +71,6 @@
static const DstRange value = OVERLAPS_RANGE;
};
-
enum RangeCheckResult {
TYPE_VALID = 0, // Value can be represented by the destination type.
TYPE_UNDERFLOW = 1, // Value would overflow.
@@ -94,15 +82,15 @@
// check by taking advantage of the fact that only NaN can be out of range in
// both directions at once.
#define BASE_NUMERIC_RANGE_CHECK_RESULT(is_in_upper_bound, is_in_lower_bound) \
- RangeCheckResult(((is_in_upper_bound) ? 0 : TYPE_OVERFLOW) | \
- ((is_in_lower_bound) ? 0 : TYPE_UNDERFLOW))
+ RangeCheckResult(((is_in_upper_bound) ? 0 : TYPE_OVERFLOW) | \
+ ((is_in_lower_bound) ? 0 : TYPE_UNDERFLOW))
template <typename Dst,
typename Src,
- DstSign IsDstSigned = std::numeric_limits<Dst>::is_signed ?
- DST_SIGNED : DST_UNSIGNED,
- SrcSign IsSrcSigned = std::numeric_limits<Src>::is_signed ?
- SRC_SIGNED : SRC_UNSIGNED,
+ DstSign IsDstSigned =
+ std::numeric_limits<Dst>::is_signed ? DST_SIGNED : DST_UNSIGNED,
+ SrcSign IsSrcSigned =
+ std::numeric_limits<Src>::is_signed ? SRC_SIGNED : SRC_UNSIGNED,
DstRange IsSrcRangeContained = StaticRangeCheck<Dst, Src>::value>
struct RangeCheckImpl {};
@@ -113,9 +101,7 @@
// Dst range always contains the result: nothing to check.
template <typename Dst, typename Src, DstSign IsDstSigned, SrcSign IsSrcSigned>
struct RangeCheckImpl<Dst, Src, IsDstSigned, IsSrcSigned, CONTAINS_RANGE> {
- static RangeCheckResult Check(Src value) {
- return TYPE_VALID;
- }
+ static RangeCheckResult Check(Src value) { return TYPE_VALID; }
};
// Signed to signed narrowing.
@@ -123,13 +109,13 @@
struct RangeCheckImpl<Dst, Src, DST_SIGNED, SRC_SIGNED, OVERLAPS_RANGE> {
static RangeCheckResult Check(Src value) {
typedef std::numeric_limits<Dst> DstLimits;
- return DstLimits::is_iec559 ?
- BASE_NUMERIC_RANGE_CHECK_RESULT(
- value <= static_cast<Src>(DstLimits::max()),
- value >= static_cast<Src>(DstLimits::max() * -1)) :
- BASE_NUMERIC_RANGE_CHECK_RESULT(
- value <= static_cast<Src>(DstLimits::max()),
- value >= static_cast<Src>(DstLimits::min()));
+ return DstLimits::is_iec559
+ ? BASE_NUMERIC_RANGE_CHECK_RESULT(
+ value <= static_cast<Src>(DstLimits::max()),
+ value >= static_cast<Src>(DstLimits::max() * -1))
+ : BASE_NUMERIC_RANGE_CHECK_RESULT(
+ value <= static_cast<Src>(DstLimits::max()),
+ value >= static_cast<Src>(DstLimits::min()));
}
};
@@ -139,7 +125,7 @@
static RangeCheckResult Check(Src value) {
typedef std::numeric_limits<Dst> DstLimits;
return BASE_NUMERIC_RANGE_CHECK_RESULT(
- value <= static_cast<Src>(DstLimits::max()), true);
+ value <= static_cast<Src>(DstLimits::max()), true);
}
};
@@ -148,9 +134,10 @@
struct RangeCheckImpl<Dst, Src, DST_SIGNED, SRC_UNSIGNED, OVERLAPS_RANGE> {
static RangeCheckResult Check(Src value) {
typedef std::numeric_limits<Dst> DstLimits;
- return sizeof(Dst) > sizeof(Src) ? TYPE_VALID :
- BASE_NUMERIC_RANGE_CHECK_RESULT(
- value <= static_cast<Src>(DstLimits::max()), true);
+ return sizeof(Dst) > sizeof(Src)
+ ? TYPE_VALID
+ : BASE_NUMERIC_RANGE_CHECK_RESULT(
+ value <= static_cast<Src>(DstLimits::max()), true);
}
};
@@ -162,14 +149,14 @@
typedef std::numeric_limits<Src> SrcLimits;
// Compare based on max_exponent, which we must compute for integrals.
static const size_t kDstMaxExponent = sizeof(Dst) * 8;
- static const size_t kSrcMaxExponent = SrcLimits::is_iec559 ?
- SrcLimits::max_exponent :
- (sizeof(Src) * 8 - 1);
- return (kDstMaxExponent >= kSrcMaxExponent) ?
- BASE_NUMERIC_RANGE_CHECK_RESULT(true, value >= static_cast<Src>(0)) :
- BASE_NUMERIC_RANGE_CHECK_RESULT(
- value <= static_cast<Src>(DstLimits::max()),
- value >= static_cast<Src>(0));
+ static const size_t kSrcMaxExponent =
+ SrcLimits::is_iec559 ? SrcLimits::max_exponent : (sizeof(Src) * 8 - 1);
+ return (kDstMaxExponent >= kSrcMaxExponent)
+ ? BASE_NUMERIC_RANGE_CHECK_RESULT(true,
+ value >= static_cast<Src>(0))
+ : BASE_NUMERIC_RANGE_CHECK_RESULT(
+ value <= static_cast<Src>(DstLimits::max()),
+ value >= static_cast<Src>(0));
}
};