OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_ | 5 #ifndef BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_ |
6 #define BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_ | 6 #define BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_ |
7 | 7 |
8 #include <limits.h> | 8 #include <limits.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 // Dst range is statically determined to contain Src: Nothing to check. | 181 // Dst range is statically determined to contain Src: Nothing to check. |
182 template <typename Dst, | 182 template <typename Dst, |
183 typename Src, | 183 typename Src, |
184 IntegerRepresentation DstSign, | 184 IntegerRepresentation DstSign, |
185 IntegerRepresentation SrcSign> | 185 IntegerRepresentation SrcSign> |
186 struct DstRangeRelationToSrcRangeImpl<Dst, | 186 struct DstRangeRelationToSrcRangeImpl<Dst, |
187 Src, | 187 Src, |
188 DstSign, | 188 DstSign, |
189 SrcSign, | 189 SrcSign, |
190 NUMERIC_RANGE_CONTAINED> { | 190 NUMERIC_RANGE_CONTAINED> { |
191 static constexpr RangeConstraint Check(Src value) { return RANGE_VALID; } | 191 static constexpr RangeConstraint Check(Src /*value*/) { return RANGE_VALID; } |
192 }; | 192 }; |
193 | 193 |
194 // Signed to signed narrowing: Both the upper and lower boundaries may be | 194 // Signed to signed narrowing: Both the upper and lower boundaries may be |
195 // exceeded. | 195 // exceeded. |
196 template <typename Dst, typename Src> | 196 template <typename Dst, typename Src> |
197 struct DstRangeRelationToSrcRangeImpl<Dst, | 197 struct DstRangeRelationToSrcRangeImpl<Dst, |
198 Src, | 198 Src, |
199 INTEGER_REPRESENTATION_SIGNED, | 199 INTEGER_REPRESENTATION_SIGNED, |
200 INTEGER_REPRESENTATION_SIGNED, | 200 INTEGER_REPRESENTATION_SIGNED, |
201 NUMERIC_RANGE_NOT_CONTAINED> { | 201 NUMERIC_RANGE_NOT_CONTAINED> { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 "Argument must be numeric."); | 256 "Argument must be numeric."); |
257 static_assert(std::numeric_limits<Dst>::is_specialized, | 257 static_assert(std::numeric_limits<Dst>::is_specialized, |
258 "Result must be numeric."); | 258 "Result must be numeric."); |
259 return DstRangeRelationToSrcRangeImpl<Dst, Src>::Check(value); | 259 return DstRangeRelationToSrcRangeImpl<Dst, Src>::Check(value); |
260 } | 260 } |
261 | 261 |
262 } // namespace internal | 262 } // namespace internal |
263 } // namespace base | 263 } // namespace base |
264 | 264 |
265 #endif // BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_ | 265 #endif // BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_ |
OLD | NEW |