Bug 61512 - libstd++ postfix operator hangs
Summary: libstd++ postfix operator hangs
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.7
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-15 15:29 UTC by Rohit Sharma
Modified: 2014-06-16 17:32 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
testcase files- source code, pre-processed code, assembly code, object code and executable (78.70 KB, application/x-gzip)
2014-06-15 15:29 UTC, Rohit Sharma
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rohit Sharma 2014-06-15 15:29:59 UTC
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;
}
Comment 1 Marc Glisse 2014-06-15 16:44:52 UTC
You are not allowed to call ++ on an iterator if calling * on it would be illegal.
Comment 2 Rohit Sharma 2014-06-16 00:09:20 UTC
(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?
Comment 3 Marc Glisse 2014-06-16 04:43:04 UTC
No, the bug is in your code. Try compiling with -D_GLIBCXX_DEBUG for a more meaningful output.
Comment 4 Jonathan Wakely 2014-06-16 07:17:16 UTC
Invalid, do not increment a non-incrementable iterator.
Comment 5 Rohit Sharma 2014-06-16 13:39:22 UTC
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
Comment 6 Marc Glisse 2014-06-16 17:14:32 UTC
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
}
Comment 7 Rohit Sharma 2014-06-16 17:32:11 UTC
Yes, it did print that message clearly before core-dump.

thank you much.
-Rohit