constexpr all of base/numerics |
||||
Issue descriptionNow that we have constexpr support, make all of the base/numerics APIs constexpr compliant.
,
Nov 8 2016
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/00c1837ccba1c6da4cb1e9b26539a6c3801bb2fb commit 00c1837ccba1c6da4cb1e9b26539a6c3801bb2fb Author: jschuh <jschuh@chromium.org> Date: Tue Nov 08 04:59:34 2016 Make checked_cast a constexpr Wraps the CHECK in a handler. This makes the non-CHECK case a clean constexpr, and has the nice effect of throwing a compile error if the compile-time evaluation can determine that a runtime CHECK would hit. Also had to fix a few incorrect uses of base::checked_cast (hence the need for the NOPRESUBMIT to cover the media directory). BUG=612995 NOPRESUBMIT=true TBR=vabr@chromium.org,hubbe@chromium.org,dmurph@chromium.org Review-Url: https://codereview.chromium.org/2481903002 Cr-Commit-Position: refs/heads/master@{#430519} [modify] https://crrev.com/00c1837ccba1c6da4cb1e9b26539a6c3801bb2fb/base/numerics/safe_conversions.h [modify] https://crrev.com/00c1837ccba1c6da4cb1e9b26539a6c3801bb2fb/base/numerics/safe_numerics_unittest.cc [modify] https://crrev.com/00c1837ccba1c6da4cb1e9b26539a6c3801bb2fb/components/autofill/core/common/save_password_progress_logger.cc [modify] https://crrev.com/00c1837ccba1c6da4cb1e9b26539a6c3801bb2fb/media/formats/mp2t/es_parser_h264.cc [modify] https://crrev.com/00c1837ccba1c6da4cb1e9b26539a6c3801bb2fb/storage/browser/blob/blob_data_builder.cc
,
Nov 22 2016
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/3223ae27f45270fc80e247d473c9cb8c19e91aa8 commit 3223ae27f45270fc80e247d473c9cb8c19e91aa8 Author: jschuh <jschuh@chromium.org> Date: Tue Nov 22 03:35:48 2016 Convert simple CheckedNumeric functions to constexpr NOTRY=true TBR=tsepez@chromium.org BUG=612995 Review-Url: https://codereview.chromium.org/2522543002 Cr-Commit-Position: refs/heads/master@{#433775} [modify] https://crrev.com/3223ae27f45270fc80e247d473c9cb8c19e91aa8/base/numerics/safe_math.h [modify] https://crrev.com/3223ae27f45270fc80e247d473c9cb8c19e91aa8/base/numerics/safe_math_impl.h
,
Jan 3 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/7308c7f7745c8bce834250d1a93e3c4501c65ca4 commit 7308c7f7745c8bce834250d1a93e3c4501c65ca4 Author: jschuh <jschuh@chromium.org> Date: Tue Jan 03 23:09:34 2017 Convert remaining CheckedNumeric unary operators to constexpr This swaps out some unnecessarily complex checked functions with simpler wrappers that support constexpr. BUG=612995 Review-Url: https://codereview.chromium.org/2612443002 Cr-Commit-Position: refs/heads/master@{#441239} [modify] https://crrev.com/7308c7f7745c8bce834250d1a93e3c4501c65ca4/base/numerics/safe_math.h [modify] https://crrev.com/7308c7f7745c8bce834250d1a93e3c4501c65ca4/base/numerics/safe_math_impl.h
,
Jul 26 2017
,
Jul 26 2017
,
Sep 2 2017
,
Oct 1 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/3725ec39917fea4cc350f0abb8dde4552e955054 commit 3725ec39917fea4cc350f0abb8dde4552e955054 Author: Justin Schuh <jschuh@chromium.org> Date: Sun Oct 01 03:44:27 2017 Make ClampedNumeric and CheckedNumeric constexpr Convert the remaining CheckedNumeric and ClampedNumeric methods to be fully C++14 constexpr compliant. This also includes the following dependent changes: * The constexpr allowed some compile-time optimizations in ClampedAddOp and ClampedSubOp, which required restructuring the overflow handling to get correct saturation semantics. (New tests cover this.) * The Clamped*FastAsmOp implementations included redundant saturation code, which was removed. Bug: 612995 Change-Id: I0e0397968712ee06f8beff2f74c638cab01f34bb Reviewed-on: https://chromium-review.googlesource.com/603127 Reviewed-by: Daniel Cheng <dcheng@chromium.org> Commit-Queue: Justin Schuh <jschuh@chromium.org> Cr-Commit-Position: refs/heads/master@{#505494} [modify] https://crrev.com/3725ec39917fea4cc350f0abb8dde4552e955054/base/numerics/checked_math.h [modify] https://crrev.com/3725ec39917fea4cc350f0abb8dde4552e955054/base/numerics/checked_math_impl.h [modify] https://crrev.com/3725ec39917fea4cc350f0abb8dde4552e955054/base/numerics/clamped_math.h [modify] https://crrev.com/3725ec39917fea4cc350f0abb8dde4552e955054/base/numerics/clamped_math_impl.h [modify] https://crrev.com/3725ec39917fea4cc350f0abb8dde4552e955054/base/numerics/safe_math_clang_gcc_impl.h [modify] https://crrev.com/3725ec39917fea4cc350f0abb8dde4552e955054/base/numerics/safe_math_shared_impl.h [modify] https://crrev.com/3725ec39917fea4cc350f0abb8dde4552e955054/base/safe_numerics_unittest.cc
,
Oct 13 2017
The commit above broke GCC builds (I've tested 6.3.0 and 7.2.1):
../../base/numerics/checked_math_impl.h: In instantiation of ‘static constexpr bool base::internal::CheckedSubOp<T, U, typename std::enable_if<(std::is_integral<_Tp>::value && std::is_integral<_Tp2>::value)>::type>::Do(T, U, V*) [with V = short unsigned int; T = short unsigned int; U = short unsigned int]’:
../../base/numerics/checked_math.h:245:29: required from ‘constexpr base::internal::CheckedNumeric<T>& base::internal::CheckedNumeric<T>::MathOp(R) [with M = base::internal::CheckedSubOp; R = short unsigned int; T = short unsigned int]’
../../base/numerics/checked_math.h:340:1: required from ‘constexpr base::internal::CheckedNumeric<T>& base::internal::CheckedNumeric<T>::operator-=(R) [with Src = short unsigned int; T = short unsigned int]’
../../base/metrics/histogram_samples.cc:145:20: required from here
../../base/numerics/checked_math_impl.h:130:15: error: uninitialized variable ‘presult’ in ‘constexpr’ function
Promotion presult;
^~~~~~~
,
Oct 19 2017
Friendly ping |
||||
►
Sign in to add a comment |
||||
Comment 1 by bugdroid1@chromium.org
, May 19 2016