Created attachment 32942 [details] testcase files- source code, pre-processed code, assembly code, object code and executable Following code hangs forever in postfix operator. #include <iostream> #include <set> int main() { std::set<int> empty; std::set<int>::iterator iter = empty.begin() ; while (iter++ != empty.end()) { std::cout << *iter << "\n"; } return 0; }
You are not allowed to call ++ on an iterator if calling * on it would be illegal.
(In reply to Marc Glisse from comment #1) > You are not allowed to call ++ on an iterator if calling * on it would be > illegal. I may agree to your comment Marc. Hanging code is manifestation is a sure bug - either in libstdc++ or gcc. Do you agree?
No, the bug is in your code. Try compiling with -D_GLIBCXX_DEBUG for a more meaningful output.
Invalid, do not increment a non-incrementable iterator.
Thank you Marc for the flag. Compiling with that flag and running it, code "abort (core dumped)" - which I take is reasonable behavior on a bad code. bests. -Rohit
Really? With _GLIBCXX_DEBUG, your program is supposed to print the following message (even with the old gcc-4.4 you reported this against): /usr/include/c++/4.8/debug/safe_iterator.h:307:error: attempt to increment a past-the-end iterator. Objects involved in the operation: iterator "this" @ 0x0x7fff4a666fb0 { type = N11__gnu_debug14_Safe_iteratorISt23_Rb_tree_const_iteratorIiENSt7__debug3setIiSt4lessIiESaIiEEEEE (mutable iterator); state = past-the-end; references sequence with type `NSt7__debug3setIiSt4lessIiESaIiEEE' @ 0x0x7fff4a666fe0 }
Yes, it did print that message clearly before core-dump. thank you much. -Rohit