gcc produces codes that segfaults.
The following program segfaults when compiled for 64-bit code on an x86-64
linux system. The program should sort a vector of doubles into descending
order.

I tested with versions 3.3.6, 3.4.6, 4.1.2, 4.2.3, 4.3.2 and 4.3.3.
- When compiling for 32-bit code (-m32) does work as expected.
- When using (std::greater_equal <double> ()) instead of std::not2 (std::less
<double> ()), the program works as expected, these should be equivalent.
- When using std::stable_sort instead of std::sort, works as expected.

Since the code fails for so many versions my guess is, that it has something to
do with the stl-not2 construct. But since the 32-bit version is o.k., it has
something to do with compiler, too, i guess.

This test program is as far stripped as i could without going into the depths
of the stl.

--- test-program:
#include <iostream>
#include <algorithm>
#include <vector>

static double data[100] = {
  3.00, 7.70, 9.40, 0.80, 5.20, 0.80, 8.70, 2.00, 0.00, 1.90,
  7.60, 9.10, 5.50, 1.80, 5.30, 7.80, 6.90, 8.80, 9.10, 5.10,
  5.10, 7.40, 7.40, 3.50, 5.40, 6.70, 0.50, 2.10, 1.80, 4.90,
  0.50, 2.70, 0.00, 2.00, 0.20, 6.70, 3.90, 3.60, 1.80, 3.60,
  6.30, 9.30, 7.40, 8.30, 4.70, 0.90, 6.60, 7.40, 5.50, 0.20,
  8.90, 1.70, 0.50, 1.20, 1.20, 7.30, 7.60, 1.20, 7.60, 2.20,
  9.70, 6.10, 2.80, 6.00, 7.50, 9.00, 3.00, 7.30, 5.60, 6.60,
  1.80, 9.70, 1.00, 6.60, 0.40, 9.40, 2.30, 1.60, 9.50, 1.00,
  8.80, 1.50, 3.80, 6.10, 3.10, 6.30, 3.90, 2.80, 2.50, 7.70,
  5.10, 0.40, 6.30, 2.10, 0.20, 2.50, 4.00, 7.40, 8.80, 2.40
};

typedef std::vector <double> dbl_vec;
int main (int argc, char **argv)
{
  dbl_vec dv (&data[0], &data[100]);

  std::sort (dv.begin (), dv.end (),
    std::not2 (std::less <double> ()));
}


-- 
           Summary: bad code for std::sort, std::not2, 64-bit, many versions
           Product: gcc
           Version: 4.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rassahah at neofonie dot de
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39144

Reply via email to