The following testing code does correctly in VS either with debug or release, so does it in gcc. It also does correctly for ICC with debug, but not when optimization enabled (-O2).
#include <cstdio>
class tClassA{
public:
int m_first, m_last;
bool isEmpty() const {return (m_first == m_last);}
void updateFirst() {m_first = m_first + 1;}
void updateLast() {m_last = m_last + 1;}
tClassA() : m_first(0), m_last(0) {}
~tClassA() {}
void doSomething() {printf("should not reach here\r\n");}
};
int main() {
tClassA q;
while(true) {
while(q.isEmpty()) ;
q.doSomething();
}
return 1;
}
It is supposed to stoped at while(q.isEmpty()). When -O2 enabled under ICC (release), however, it starts to "doSomething" infintely.
Since this is single-threaded program AND isEmpty() should be evaluated as "true", I can find no reason the ICC should behave in this way? Do I miss anything?