Tying a C++ iostream object to itself causes a stack overflow in visual studio 2012 - by Davis King

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 772293 Comments
Status Closed Workarounds
Type Bug Repros 3
Opened 11/26/2012 5:21:00 PM
Access Restriction Public


The following code will cause a stack overflow in visual studio 2012 express:

#include <iostream>

int main()
   std::cout << "boom";

I looked in the standard and it seems that you should be allowed to tie a stream to itself.  This is a somewhat silly example but it is useful in other cases.  For example, in the asio networking library it is useful and common to have a tcp iostream tied to itself so that read attempts cause automatic flushing.  

Other people seem to have run into this problem as well.  For example, see: http://stackoverflow.com/questions/11924601/runtime-error-of-boost-asynchronous-i-o-example

The poster at stackoverflow.com is experiencing the same error as I am.  In particular, what happens is that ostream::flush() constructs a sentry which then calls ostream::flush() and this repeats until the stack runs out.
Sign in to post a comment.
Posted by Microsoft on 4/29/2014 at 12:31 PM
Thank you for reporting this issue. This issue has been fixed in Visual Studio 2013. You can install a trial version of Visual Studio 2013 with the fix from: http://go.microsoft.com/?linkid=9832436
Posted by Microsoft on 2/28/2013 at 4:47 PM

Thanks for reporting this bug. We've fixed it, and the fix will be available in VC12. (Note: VC8 = VS 2005, VC9 = VS 2008, VC10 = VS 2010, VC11 = VS 2012.)

Note: Connect doesn't notify me about comments. If you have any further questions, please E-mail me.

Stephan T. Lavavej
Senior Developer - Visual C++ Libraries
Posted by Microsoft on 11/27/2012 at 2:10 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 11/26/2012 at 5:53 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)