http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47861
--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-02-24 10:44:15 UTC --- (In reply to comment #7) > The issue is clearly caused by having > declared static the iterator. So that's a bug, don't do that. > Obviously the same snippet code can be > replaced by a simple for each iterator construct. > As you have mentioned > before - static means static...consider only the implication of a code > written in this way...a > forced definition of the iterator being static > would probably prevent some unprapred c++ users to make similar > mistakes. I don't understand, are you now suggesting the local static should be turned into a static member by the compiler?! Again, please explain what warning you want. So far you've shown some buggy code, but haven't explained how GCC could help prevent users from creating that bug. e.g. foo.cc:4:3: In 'MyClass::next(bool)': foo.cc:4:3: Warning: 'it' is declared as a function-scope static, did you want to use a static member variable? For the record, I would be strongly-opposed to such a warning. There are a million ways to write code that is buggy, the compiler cannot possibly infer what you really wanted to do and suggest how to fix all bugs.