https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125624

            Bug ID: 125624
           Summary: C++23: support of std::float16_t for
                    std::uniform_real_distribution
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: [email protected]
  Target Milestone: ---

Created attachment 64637
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64637&action=edit
Test program

C++23 comes with support of <stdfloat> which includes optional fixed-width
floating point types like std::float16_t etc. which are all supported by g++-15
or g++-16. Support of std::uniform_real_distribution<T> is provided by the
associated C++ standard library for most of these types but not for
std::float16_t. The problem is not the missing support but how it fails.

All tests have been run on an Linux system with self-built g++ versions (15.2.0
and 16.1.0) with configure options “--prefix=/opt/gcc/XX
--enable-languages=c,c++,fortran --program-suffix=-XX --disable-multilib” for
XX = 15 and 16, respectively.

In case of g++-15, std::uniform_real_distribution<std::float16_t> can be
instantiated and the generating function operator can be used but always
deliver NaN values. Attached test program delivers following output:

std::uniform_real_distribution<std::float16_t>{}(gen) delivers NaN
std::uniform_real_distribution<std::float32_t>{}(gen) appears to work as
expected
std::uniform_real_distribution<std::float64_t>{}(gen) appears to work as
expected
std::uniform_real_distribution<std::float128_t>{}(gen) appears to work as
expected
std::uniform_real_distribution<std::bfloat16_t>{}(gen) appears to work as
expected

In case of g++-16, std::uniform_real_distribution<std::float16_t> can be
likewise instantiated but delivers a compilation error due to a static
assertion:

/opt/gcc/16/include/c++/16.1.0/bits/random.tcc:3708:23: error: static assertion
failed: float16_t type is not supported, consider using bfloat16_t
 3708 |       static_assert(! is_same_v<_RealT, _Float16>,
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  • ‘!(bool)std::is_same_v<_Float16, _Float16>’ evaluates to false

While this appears to be a helpful message, the static_assert allows not to
defend against this using concepts or requires-clauses.

Reply via email to