PR68925 don't use thread_local static for stateless object
authorJonathan Wakely <jwakely@redhat.com>
Wed, 18 Jan 2017 17:18:47 +0000 (17:18 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 18 Jan 2017 17:18:47 +0000 (17:18 +0000)
PR libstdc++/68925
* include/experimental/random (randint): Use temporary instead of
thread_local static.

From-SVN: r244584

libstdc++-v3/ChangeLog
libstdc++-v3/include/experimental/random

index a499ae78d34810bbb46064a7454c15e52fd36097..6b5135757c0b607a1f501a4a6b8ebaeddffd0b96 100644 (file)
@@ -1,3 +1,9 @@
+2017-01-18  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR libstdc++/68925
+       * include/experimental/random (randint): Use temporary instead of
+       thread_local static.
+
 2017-01-17  Joshua Conner  <joshconner@google.com>
 
        * crossconfig.m4: Add fuchsia OS.
index 9d5415ede17f2a5319fe42c5e576309375603222..e28df5df7213db2c25d4e04ed02704bacb5822aa 100644 (file)
@@ -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