Boost C++ Libraries: Ticket #11699: Forward declarations of std templates causes stack corruption under Visual Studio 2015 https://svn.boost.org/trac10/ticket/11699 <p> In Visual Studio 2015 it can lead to stack corruption if I instantiate std::basic_istream with the same types in two compilation units, and one of them forward declares the template and the other doesn't. </p> <p> I originally run into this problem when I called a funtion in a library that called boost::lexical_cast. The source file containing the function included a header from interprocess, which included interprocess/detail/std_fwd.hpp which contains a forward declaration of std::basic_istream. </p> <p> Unfortunately std::basic_istream was also instatiated with the same types in my main program (but there was no forward declaration). </p> <p> I presume this can happen with other templates as well, but so far this is the only one I found. </p> <p> The same code was working fine with Visual Studio 2013. </p> <p> I created two small solutions: </p> <ul><li>BoostStackCorruption_VS2015: using boost::lexical_cast and an interprocess header </li><li>StdStackCorruption_VS2015: using only std but with lines coming from the insides of lexical_cast and interprocess/detail/std_fwd.hpp </li></ul> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11699 Trac 1.4.3 Attila Mitrócsák <attila.mitrocsak@…> Wed, 30 Sep 2015 16:14:32 GMT attachment set https://svn.boost.org/trac10/ticket/11699 https://svn.boost.org/trac10/ticket/11699 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">StdStackCorruption_VS2015.zip</span> </li> </ul> <p> Stack corruption with std only </p> Ticket Attila Mitrócsák <attila.mitrocsak@…> Wed, 30 Sep 2015 16:14:56 GMT attachment set https://svn.boost.org/trac10/ticket/11699 https://svn.boost.org/trac10/ticket/11699 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">BoostStackCorruption_VS2015.zip</span> </li> </ul> <p> Stack corruption with boost </p> Ticket Ion Gaztañaga Wed, 30 Sep 2015 20:19:16 GMT <link>https://svn.boost.org/trac10/ticket/11699#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11699#comment:1</guid> <description> <p> Thanks for the report. It seems that it is a compiler bug, and standard libraries before Visual 2013 used some dummy virtual functions in basic_istream and basic_ostream to fix it. Starting with Visual 2013 &lt;istream&gt; and &lt;ostream&gt; contain a pragma to fix the bug with the comment: </p> <pre class="wiki"> #pragma vtordisp(push, 2) // compiler bug workaround </pre><p> The fix is to use the same pragma when forward declaring the basic_istream and basic_ostream. </p> <p> Thanks a lot for the detailed report and MSVC solutions, they helped a lot. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Wed, 30 Sep 2015 20:27:34 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/11699#comment:2 https://svn.boost.org/trac10/ticket/11699#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fixed in develop branch, soon to be merged to master. Commit: </p> <p> <a class="ext-link" href="https://github.com/boostorg/interprocess/commit/845d352287902b535b75b5545ff448744fa79820"><span class="icon">​</span>https://github.com/boostorg/interprocess/commit/845d352287902b535b75b5545ff448744fa79820</a> </p> Ticket Attila Mitrócsák <attila.mitrocsak@…> Thu, 01 Oct 2015 09:00:06 GMT <link>https://svn.boost.org/trac10/ticket/11699#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11699#comment:3</guid> <description> <p> Thanks for the fast fix. </p> <p> Does that mean that only std::basic_istream and std::basic_ostream are affected? Can we be sure that all the other forward declarations of templates in std used by boost are safe? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Thu, 01 Oct 2015 14:37:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11699#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11699#comment:4</guid> <description> <p> Those are the only classes in the MSVC STL that are marked with that bug-fixing pragma. It's related to virtual inheritance, and only ios classes use that type of inheritance. We can't be 100% sure, but I'm pretty confident about that. </p> </description> <category>Ticket</category> </item> <item> <author>Attila Mitrócsák <attila.mitrocsak@…></author> <pubDate>Thu, 01 Oct 2015 14:53:22 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11699#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11699#comment:5</guid> <description> <p> Ok, thanks. </p> </description> <category>Ticket</category> </item> </channel> </rss>