T
Thorsten Raasch
Hi,
the following C++ program seems to yield a segmentation fault
in g++ 3.4 when compiled with any of the optimization options -O*,
e.g. with "g++ -O2 bug.cpp -o bug".
class TestClass {
public:
TestClass() {
c[0] = 1;
c[1] = 2;
}
int f(const unsigned int i) { // segfault during optimization
// int f(unsigned int i) { // works fine
return c[(i==1) ? 1 : 0];
}
int c[2];
};
int main()
{
TestClass c;
int x = c.f(1);
return 0;
}
I tested the code with g++ 3.4 under Debian, CentOS and SunOS, resulting
in a segmentation fault in each case. Can anyone confirm the bug?
First, the point seems to be that the argument of the method f is a
"const unsigned int". Changing the argument either into a "const int" or
an "unsigned int" indeed yields a compileable code.
Second point: if the return value is just (i==1) ? 1 : 0, the code also
compiles fine.
Best,
Thorsten Raasch
the following C++ program seems to yield a segmentation fault
in g++ 3.4 when compiled with any of the optimization options -O*,
e.g. with "g++ -O2 bug.cpp -o bug".
class TestClass {
public:
TestClass() {
c[0] = 1;
c[1] = 2;
}
int f(const unsigned int i) { // segfault during optimization
// int f(unsigned int i) { // works fine
return c[(i==1) ? 1 : 0];
}
int c[2];
};
int main()
{
TestClass c;
int x = c.f(1);
return 0;
}
I tested the code with g++ 3.4 under Debian, CentOS and SunOS, resulting
in a segmentation fault in each case. Can anyone confirm the bug?
First, the point seems to be that the argument of the method f is a
"const unsigned int". Changing the argument either into a "const int" or
an "unsigned int" indeed yields a compileable code.
Second point: if the return value is just (i==1) ? 1 : 0, the code also
compiles fine.
Best,
Thorsten Raasch