Alvaro Herrera <alvhe...@alvh.no-ip.org> writes: > Tom Lane wrote: >> Actually, on looking closer, it's more likely got something to do with >> whether or not you used --enable-cassert. If the Assert at the top of >> the function is disabled, then IMO a compiler that failed to complain >> about this coding would be pretty damn broken.
> I tried removing the Assert, and my compiler doesn't complain. I > noticed that the function is static and the only caller has its own > assert about ntapes; yet removing that one doesn't cause a warning > either. I made the function non-static -- still no warning. If I make the function non-static, I get a warning (note you can't just remove the "static" on the function itself, you also have to change the forward declaration earlier in the file). Marking the function pg_noinline also results in a warning. It is darn weird that there's no warning after inlining --- the caller is only asserting ntapes > 0, which is not strong enough to prove that the loop must be iterated. Moreover, I see the warning even if I leave in the "Assert(lts->nTapes >= 2)" ... so my compiler, at least, is not using those assertions to prove the loop must iterate. I notice that, because "lt" is initialized to NULL, the compiler might feel it can assume that the loop iterated at least once if control gets to the use of tapeblocks. But the whole thing still seems weird. I think we must be looking at some squishy spots in gcc's rules about when to issue a warning. regards, tom lane