The following code gives different results with -O3 (or -O2) and no optimization.The -O3 output is wrong. try: $g++ -O3 test.cpp $cat test.cpp #include <iostream> class foo { int _type; public: foo( int t ) : _type(t) {}; bool is_1() { return _type == 1; } bool is_23() { return _type == 2 || _type == 3; } }; void testit( foo& e1, foo& e2 ) { if ( e1.is_1() && e2.is_1() ) std::cout << "If - 1.1\n"; else if ( e1.is_23() && e2.is_23() ) std::cout << "If - 23.23\n"; else if ( e1.is_1() && e2.is_23() ) std::cout << "If - 1.23\n"; else if ( e1.is_23() && e2.is_1() ) std::cout << "If - 23.1\n"; else std::cout << "If - bad\n"; } int main() { for ( int i = 1; i < 4; ++i ) for ( int j = 1; j < 4; ++j ) { foo e1(i); foo e2(j); testit( e1, e2 ); } return 0; } result with -O3 : $./a.out If - 1.1 If - 1.23 If - 1.23 If - 23.1 If - 23.23 If - 23.23 If - bad If - 23.23 If - 23.23 result without optimization : $./a.out If - 1.1 If - 1.23 If - 1.23 If - 23.1 If - 23.23 If - 23.23 If - 23.1 If - 23.23 If - 23.23 satya
This works for me on x86_64 and i686. Possibly a rtl-optimization or target bug. As there were loop fixes after 4.1.2 went out can you try with the trunk of the gcc-4_1-branch or give the exact version of your compiler (gcc --version will tell)?
it is gcc 4.1.2 the base release. Satya
Works fine with GCC 4.2.x and later.