summaryrefslogtreecommitdiff
path: root/absl/random
diff options
context:
space:
mode:
authorGravatar Derek Mauro <dmauro@google.com>2023-03-20 12:18:53 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2023-03-20 12:19:48 -0700
commite5067964adcb792b7c9dbddbdcfe4d9b94079597 (patch)
treecdd231fd259cef020bbb8f559b8086e6a570f63e /absl/random
parentf959f6ba970d9b2fef4fd2eb084668651dacf961 (diff)
Fix an implicit truncation warning under MSVC 32-bit
Since the return value of `NumBits()` will always fit into `size_t`, use an explicit cast to silence the implicit conversion warning. Fixes #1384 PiperOrigin-RevId: 518041598 Change-Id: If2f2456db4b27b78e9ea9e026dce610953bd5bfb
Diffstat (limited to 'absl/random')
-rw-r--r--absl/random/internal/fast_uniform_bits.h7
1 files changed, 4 insertions, 3 deletions
diff --git a/absl/random/internal/fast_uniform_bits.h b/absl/random/internal/fast_uniform_bits.h
index 8d8ed045..83ee5c0f 100644
--- a/absl/random/internal/fast_uniform_bits.h
+++ b/absl/random/internal/fast_uniform_bits.h
@@ -57,9 +57,10 @@ constexpr UIntType IntegerLog2(UIntType n) {
// `PowerOfTwoVariate(urbg)`.
template <typename URBG>
constexpr size_t NumBits() {
- return RangeSize<URBG>() == 0
- ? std::numeric_limits<typename URBG::result_type>::digits
- : IntegerLog2(RangeSize<URBG>());
+ return static_cast<size_t>(
+ RangeSize<URBG>() == 0
+ ? std::numeric_limits<typename URBG::result_type>::digits
+ : IntegerLog2(RangeSize<URBG>()));
}
// Given a shift value `n`, constructs a mask with exactly the low `n` bits set.