I have some code like this:
void splay(const size_t x) {
for (const size_t& nxfa = nodes.at(x).father; nxfa;) {
normalize(nxfa);
const Node& nf = nodes.at(nxfa);
if (nf.lch) normalize(nf.lch);
if (nf.rch) normalize(nf.rch);
rotate(x == nf.lch ? 'R' : 'L', x);
}
}
In the for-loop condition, clang-diagnostic-for-loop-analysis tool complains "variable 'nxfa' used in loop condition not modified in loop body."
However, inlined function call rotate will modify the object nxfa references to, just we do not use nxfa (the const_reference) to modify it.
It's a legal usage so just a false alarm by tool, correct? Thanks.
BTW, now I can workaround it by the following code:
void splay(const size_t x) {
while (nodes.at(x).father) {
const size_t nxfa = nodes.at(x).father;
normalize(nxfa);
const Node& nf = nodes.at(nxfa);
if (nf.lch) normalize(nf.lch);
if (nf.rch) normalize(nf.rch);
rotate(x == nf.lch ? 'R' : 'L', x);
}
}
Yes, this is legal. You should report a bug to your static analyzer.