#does clang have a warning for infinite for loops?

16 messages · Page 1 of 1 (latest)

hearty citrus
#

for(int i = 0; grid->rows; ++i)
This compiles fine with all warnings turned on.

plucky copperBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

rugged atlas
#

how do you expect clang would warn you about that? does clang know that the body of the loop won't modify grid->rows in any way? do you expect it to analyze your code to ensure all loops eventually terminate?

sleek widget
flat girder
flat girder
sleek widget
flat girder
sleek widget
#

They shouldn't, but I bet at least a few people do

hearty citrus
#

I usually use a while loop for infinite loops. maybe a warning if the condition is not the result of comparison and logical operators.

#

warnings are nice i do not expect myself to have an answer 100% of the time and seeing a warning would be faster than breaking out a debugger. Also the inner logic of the loop could have been wrong like if it were a flood fill algorithm.

#

Your authoritative answers are annoying without providing any explanation as to why you think you are right.

#

and i know infinite loops exist just in the context of a for it doesnt not make much sense.

hearty citrus
#

.close

#

!close