Skip to content

Commit

Permalink
Fix implicit conversion of temporary bitgen to BitGenRef
Browse files Browse the repository at this point in the history
There is no reason a temporary *shouldn't* be usable with BitGenRef (indeed, ABSL_ATTRIBUTE_LIFETIME_BOUND should catch errors) and it is useful when passing a temporary bitgen as an input argument.

PiperOrigin-RevId: 642021132
Change-Id: I03e46f5f437e40a0c6225ea1f0361475a3501513
  • Loading branch information
Abseil Team authored and Copybara-Service committed Jun 10, 2024
1 parent 1d401d9 commit cb319b3
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions absl/random/bit_gen_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,21 @@ class BitGenRef {
BitGenRef& operator=(const BitGenRef&) = default;
BitGenRef& operator=(BitGenRef&&) = default;

template <typename URBG, typename absl::enable_if_t<
(!std::is_same<URBG, BitGenRef>::value &&
random_internal::is_urbg<URBG>::value &&
!HasInvokeMock<URBG>::value)>* = nullptr>
BitGenRef(URBG& gen ABSL_ATTRIBUTE_LIFETIME_BOUND) // NOLINT
template <
typename URBGRef, typename URBG = absl::remove_cvref_t<URBGRef>,
typename absl::enable_if_t<(!std::is_same<URBG, BitGenRef>::value &&
random_internal::is_urbg<URBG>::value &&
!HasInvokeMock<URBG>::value)>* = nullptr>
BitGenRef(URBGRef&& gen ABSL_ATTRIBUTE_LIFETIME_BOUND) // NOLINT
: t_erased_gen_ptr_(reinterpret_cast<uintptr_t>(&gen)),
mock_call_(NotAMock),
generate_impl_fn_(ImplFn<URBG>) {}

template <typename URBG,
template <typename URBGRef, typename URBG = absl::remove_cvref_t<URBGRef>,
typename absl::enable_if_t<(!std::is_same<URBG, BitGenRef>::value &&
random_internal::is_urbg<URBG>::value &&
HasInvokeMock<URBG>::value)>* = nullptr>
BitGenRef(URBG& gen ABSL_ATTRIBUTE_LIFETIME_BOUND) // NOLINT
BitGenRef(URBGRef&& gen ABSL_ATTRIBUTE_LIFETIME_BOUND) // NOLINT
: t_erased_gen_ptr_(reinterpret_cast<uintptr_t>(&gen)),
mock_call_(&MockCall<URBG>),
generate_impl_fn_(ImplFn<URBG>) {}
Expand Down

0 comments on commit cb319b3

Please sign in to comment.