From b08fdbb8450a578846ad69b00b89a80ef24a5203 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 18 Jan 2017 17:18:47 +0000 Subject: [PATCH] PR68925 don't use thread_local static for stateless object PR libstdc++/68925 * include/experimental/random (randint): Use temporary instead of thread_local static. From-SVN: r244584 --- libstdc++-v3/ChangeLog | 6 ++++++ libstdc++-v3/include/experimental/random | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index a499ae78d34..6b5135757c0 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2017-01-18 Jonathan Wakely + + PR libstdc++/68925 + * include/experimental/random (randint): Use temporary instead of + thread_local static. + 2017-01-17 Joshua Conner * crossconfig.m4: Add fuchsia OS. diff --git a/libstdc++-v3/include/experimental/random b/libstdc++-v3/include/experimental/random index 9d5415ede17..e28df5df721 100644 --- a/libstdc++-v3/include/experimental/random +++ b/libstdc++-v3/include/experimental/random @@ -54,8 +54,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static_assert(is_integral<_IntType>::value && sizeof(_IntType) > 1, "argument must be an integer type"); using _Dist = std::uniform_int_distribution<_IntType>; - static thread_local _Dist __dist; - return __dist(_S_randint_engine(), typename _Dist::param_type{__a, __b}); + // This relies on the fact our uniform_int_distribution is stateless, + // otherwise we'd need a static thread_local _Dist and pass it + // _Dist::param_type{__a, __b}. + return _Dist(__a, __b)(_S_randint_engine()); } inline void -- 2.30.2