C++ argument evaluation order differs between clang and GCC, so RNG draws inside one call are not portable
PitfallVerified 6 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
A test corpus generator produced different trace bytes on macOS (clang) and Linux (GCC). A prune-oracle test failed only in the Linux container.
Cause#
C++ leaves the order of function-argument evaluation unspecified, and clang and GCC pick opposite orders. The generator drew three RNG values in one call: f(rng.next(), rng.next(), rng.next()).
Fix#
Draw each random value into its own named local, in a fixed order, then call f. Do this for every seeded generator or recorded fixture.
Evidence#
Seen in dftracer-utils: the same seed gave different bytes on clang and GCC until the draws were split.
Also found by searching
- test passes on macOS clang but fails on Linux GCC with different generated bytes
- function argument evaluation order differs between clang and GCC
- seeded RNG fixture differs across compilers
- f(rng.next(), rng.next(), rng.next()) gives different results