Skip to content

fix universal: fix random generator initialization in C++23#1245

Open
emikg777 wants to merge 1 commit into
userver-framework:developfrom
emikg777:fix/universal-rand-cxx23-seed-seq
Open

fix universal: fix random generator initialization in C++23#1245
emikg777 wants to merge 1 commit into
userver-framework:developfrom
emikg777:fix/universal-rand-cxx23-seed-seq

Conversation

@emikg777

@emikg777 emikg777 commented Jun 6, 2026

Copy link
Copy Markdown

utils::impl::RandomImpl initialized std::mt19937 via AsLvalue(impl::MakeSeedSeq()).

This fails to compile in C++23, because returning the rvalue-reference parameter from AsLvalue is affected by the C++23 implicit move rules from P2266R3. As a result, the returned expression may no longer be treated as a non-const lvalue reference, while the seed-sequence constructor of the generator expects a non-const lvalue seed sequence.

The error is (gcc 15.2.0):

error: cannot bind non-const lvalue reference of type ‘std::seed_seq&’ to an rvalue of type ‘std::seed_seq’

This change removes the AsLvalue helper and initializes the generator from a local std::seed_seq object instead. The local object stays alive for the duration of the generator construction, and no reference to a temporary is returned.

Testing:

  • Built a userver-based project with CMAKE_CXX_STANDARD=23.
  • Built and ran userver-universal-unittest.
  • Full userver-universal-unittest run: 1671/1672 tests passed. The only failure was LogFilepath.UserverCroppedCorrectly, which appears to be path-layout-sensitive when userver is built as a CPM dependency under _deps/userver-src.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant