Bug 24062 - g++ 2.96-69 problems with STL sort() using -mcpu=i686
g++ 2.96-69 problems with STL sort() using -mcpu=i686
Status: CLOSED RAWHIDE
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
7.0
i686 Linux
medium Severity high
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-01-15 14:12 EST by Christian Bauer
Modified: 2007-04-18 12:30 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2001-01-17 10:19:13 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Christian Bauer 2001-01-15 14:12:48 EST
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

struct foo {
    foo() {}
    ~foo() {}
    foo(const string &n) : name(n), size(0), flag(false) {}

    const foo &operator=(const foo &other)
    {
        if (this != &other) {
            name = other.name;
            size = other.size;
            flag = other.flag;
        }
        return *this;
    }

    bool operator<(const foo &other) const {return name < other.name;}

    string name;
    long size;
    bool flag;
};

static void print_vec(const vector<foo> &v)
{
    vector<foo>::const_iterator i, end = v.end();
    for (i = v.begin(); i != end; i++)
        cout << " " << i->name << endl;
}

int main(void)
{
    vector<foo> v;
    v.push_back(foo("B"));
    v.push_back(foo("A"));

    cout << "Before:\n"; print_vec(v);
    sort(v.begin(), v.end());
    cout << "After:\n"; print_vec(v);

    return 0;
}

[cbauer@down cbauer]$ g++ -O1 -o test2 test2.cpp
[cbauer@down cbauer]$ ./test2
Before:
 B
 A
After:
 A
 B
[cbauer@down cbauer]$ g++ -mcpu=i686 -O1 -o test2 test2.cpp
[cbauer@down cbauer]$ ./test2
Before:
 B
 A
After:
 A
 A

The problem does not appear with "-mcpu=i586 -O1" or "-mcpu=i686 -O0".
Interestingly, the problem also disappears when removing the "size" or
"flag" member from struct foo.
Comment 1 Jakub Jelinek 2001-01-17 10:19:09 EST
Richard Henderson fixed this independently yesterday in
http://gcc.gnu.org/ml/gcc-patches/2001-01/msg01336.html
I've verified it really fixes this issue and the patch will make it into
gcc-2.96-71.

Note You need to log in before you can comment on or make changes to this bug.