This is an archive of the discontinued LLVM Phabricator instance.

Fix side effect in debug code
AbandonedPublic

Authored by eax on May 8 2018, 7:08 PM.

Details

Summary

Use "+ 1" instead of "++" for the assertion

Diff Detail

Event Timeline

eax created this revision.May 8 2018, 7:08 PM

I don't know this code well enough to LGTM this, but can you talk a bit about why, please? This side-effect-inside-an-assert looks sane to me.

zturner added a subscriber: eax.May 8 2018, 7:23 PM

It actually looks wrong to me to *not* have the side effect. If this is due
to some warning, then the increment needs to be moved after the assert

eax planned changes to this revision.May 8 2018, 7:27 PM

bah. I misread the code originally. Its less about a warning and more about an oddity when reading code. that said, I completely mis-read this and agreed, the loop index should be incremented outside of the assert.

Having the side-effect inside the assert is harmless since the #ifndef ensures the whole loop is only built when asserts are enabled and Index is only used by the assert. However, I agree it's weird to have side-effects inside the assert. Moving the increment out of the assert and into the for loop would LGTM

The whole loop is an assert. The only purpose of it is to verify the ID vs. its position in the loop. Maybe having for (unsigned i = ...; i != e; ++i) instead would be cleaner, but I think it's ok as is. I don't have a problem with changing it either, but I wouldn't say it's necessary.

eax abandoned this revision.Jun 16 2018, 8:31 PM