cpython
cpython copied to clipboard
A warning message caused by unused variable in non-debug mode
Bug report
Bug description:
A compiler warning was introduced by 15309329b65a285cb7b3071f0f08ac964b61411b in non-debug build.
static void
completed_cycle(GCState *gcstate)
{
PyGC_Head *not_visited = &gcstate->old[gcstate->visited_space^1].head;
assert(gc_list_is_empty(not_visited));
gcstate->visited_space = flip_old_space(gcstate->visited_space);
if (gcstate->work_to_do > 0) {
gcstate->work_to_do = 0;
}
}
not_visited is only used in assert which will be optimized out in non debug build, thus caused the warning of unused variable. We can
- leave the warning to be (seems bad and unprecedented)
- throw out the variable and put the value into assert directly (less readable but maybe acceptable?)
- use
NDEBUGto protect the variable declaration (easier to understand, but messier code) - use some compiler specific annotation for the variable (may not be portable?)
I don't see the perfect solution here so maybe @markshannon can call the decision?
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Does #117112 fix this?
Ah, yes. That's option 2.
Fixed in https://github.com/python/cpython/commit/e28477f214276db941e715eebc8cdfb96c1207d9, I believe (please reopen if I'm incorrect!)