libstdc++: Fix constant expressions in std::uniform_int_distribution
authorJonathan Wakely <jwakely@redhat.com>
Wed, 4 Nov 2020 10:36:45 +0000 (10:36 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 4 Nov 2020 10:36:45 +0000 (10:36 +0000)
Clang and EDG say the class member access expressions __urng.min() and
__urng.max() are not constant expressions, because the object expression
__urng is not usable in a constant expresion. Use a qualified-id to call
those static member functions instead.

Co-authored-by: Stephan Bergmann <sbergman@redhat.com>
libstdc++-v3/ChangeLog:

* include/bits/uniform_int_dist.h (uniform_int_distribution::_S_nd):
Use qualified-id to refer to static member functions.

libstdc++-v3/include/bits/uniform_int_dist.h

index 524593bb9847a0900240328f6c348016c288c68b..8f02b85c9bb0884a59bd2190fa668e507e9e1f1f 100644 (file)
@@ -278,12 +278,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        typedef typename make_unsigned<result_type>::type __utype;
        typedef typename common_type<_Gresult_type, __utype>::type __uctype;
 
-       static_assert( __urng.min() < __urng.max(),
+       constexpr __uctype __urngmin = _UniformRandomBitGenerator::min();
+       constexpr __uctype __urngmax = _UniformRandomBitGenerator::max();
+       static_assert( __urngmin < __urngmax,
            "Uniform random bit generator must define min() < max()");
-
-       constexpr __uctype __urngmin = __urng.min();
-       constexpr __uctype __urngmax = __urng.max();
        constexpr __uctype __urngrange = __urngmax - __urngmin;
+
        const __uctype __urange
          = __uctype(__param.b()) - __uctype(__param.a());