Bug 24062 - g++ 2.96-69 problems with STL sort() using -mcpu=i686
Summary: g++ 2.96-69 problems with STL sort() using -mcpu=i686
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc   
(Show other bugs)
Version: 7.0
Hardware: i686
OS: Linux
medium
high
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-01-15 19:12 UTC by Christian Bauer
Modified: 2007-04-18 16:30 UTC (History)
0 users

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


Attachments (Terms of Use)

Description Christian Bauer 2001-01-15 19:12:48 UTC
#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 15:19:09 UTC
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.