On Mon, Feb 28, 2022 at 12:29 PM Johannes Berg johannes@sipsolutions.net wrote:
If we're willing to change the API for the macro, we could do
list_for_each_entry(type, pos, head, member)
and then actually take advantage of -Wshadow?
See my reply to Willy. There is no way -Wshadow will ever happen.
I considered that (type, pos, head, member) kind of thing, to the point of trying it for one file, but it ends up as horrendous syntax. It turns out that declaring the type separately really helps, and avoids crazy long lines among other things.
It would be unacceptable for another reason too - the amount of churn would just be immense. Every single use of that macro (and related macros) would change, even the ones that really don't need it or want it (ie the good kinds that already only use the variable inside the loop).
So "typeof(pos) pos" may be ugly - but it's a very localized ugly.
Linus