Repository navigation
Tighten absl::BitGenRef binding rules and simplify its implementation. - #2294
Draft
copybara-service[bot] wants to merge 1 commit into
Draft
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
* Reject binding to const generators. Generating a variate mutates the generator, but BitGenRef previously accepted `const URBG&` and later invoked the non-const `operator()` through a cast, which is undefined behavior for generators defined const. Such constructions now resolve to a deleted constructor. * Detect `operator BitGenRef()` on an lvalue rather than an rvalue. This lets types ref-qualify the operator (`operator BitGenRef() &`) to prevent binding a BitGenRef to a temporary; previously such types were silently wrapped as a URBG instead, adding a layer of indirection. * Merge the mocking and non-mocking constructors; the mock dispatch function is now selected with `if constexpr`. * Store the generator as `void*` instead of `uintptr_t`, replacing reinterpret_casts with static_casts, and use a null mock function pointer instead of a `NotAMock` sentinel. PiperOrigin-RevId: 1004460719
copybara-service
Bot
force-pushed
the
test_1004460719
branch
from
October 22, 2026 17:48
eb2c6da to
c5c1c21
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tighten absl::BitGenRef binding rules and simplify its implementation.
generator, but BitGenRef previously accepted
const URBG&and laterinvoked the non-const
operator()through a cast, which is undefinedbehavior for generators defined const. Such constructions now resolve to
a deleted constructor.
operator BitGenRef()on an lvalue rather than an rvalue. Thislets types ref-qualify the operator (
operator BitGenRef() &) toprevent binding a BitGenRef to a temporary; previously such types were
silently wrapped as a URBG instead, adding a layer of indirection.
function is now selected with
if constexpr.void*instead ofuintptr_t, replacingreinterpret_casts with static_casts, and use a null mock function
pointer instead of a
NotAMocksentinel.