g++: strange compiler warning
g++ compiler (4.4.3-4) gives me a strange warning on the following code:
T & GetElem(int64 i) { if((i<0ll)||(i>=m_iSize)) return m_cDummy; return m_pData[i]; } Where T - template argument (it's a simple template dynamic array). m_iSize is int64 (long long). m_cDummy is T, m_pData is T* The warning is: warning: assuming signed overflow does not occur when assuming that (X - c) > X is always false Does any one know why I get this? |
Looks like gcc has optimised out your if statement (assuming that's where the warning came from), and is warning you that the optimised code may not be correct if the values overflow.
See: http://patrakov.blogspot.com/2008_10_01_archive.html Dave |
Thanks for reply. The only question is why gcc optimizes my 'if' if I use -O0 option.
|
Hmmm. I'm not particularly familiar with the details of how gcc operates internally - maybe it's not an optimisation, but just how the if comparisons are converted to machine code?
Dave |
All times are GMT -5. The time now is 08:57 PM. |