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

            Bug ID: 113761
           Summary: Abnormal program termination using libstdc++
           Product: gcc
           Version: 12.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arakawamasahiro at jp dot fujitsu.com
  Target Milestone: ---

If you compile the following program with g++-11.4.0 and run it using libstdc++
12.3.0, the executable program will terminate abnormally.

[program(test.cpp)]
#include <iostream>

#include <random>
#include <cassert>

double f(double x)
{
    return x*2;
}

int main()
{
    typedef std::piecewise_constant_distribution<> D;
    D d({}, f);
    std::vector<double> iv = d.intervals();

    return 0;
}

[Compile and execute log]
$ g++ test.cpp
$ LANG=C; ./a.out
terminate called after throwing an instance of 'std::length_error'
  what():  vector::reserve
Aborted (core dumped)

The {} specified in the first argument of variable d in the std::
piecewise_constant_distribution<> class reduces the list size to 0.
Given the constraints of the constructor of the std::
piecewise_constant_distribution<> class, you should expect a pattern where the
list size is zero.

Reply via email to