> And I doubt that GCC (or any compiler) could reliably detect code > that checks for overflow.
It doesn't need to "detect" all such code: all it needs to do is ensure that it doesn't BREAK such code. And that's a far easier condition: you just have to avoid folding a condition into TRUE or FALSE based on assumptions about overflow.