<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>STL: Destructor of Bugs</title><link>http://blogs.msdn.com/b/vcblog/archive/2007/02/26/stl-destructor-of-bugs.aspx</link><description>I'm the newest developer on the Visual C++ Libraries team. My true name is Stephan T. Lavavej, but I often use my extremely convenient initials. I moved here at the beginning of this year after working on and finishing Outlook 2007 Search. 
 
 You know</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: STL: Destructor of Bugs</title><link>http://blogs.msdn.com/b/vcblog/archive/2007/02/26/stl-destructor-of-bugs.aspx#3601680</link><pubDate>Fri, 29 Jun 2007 14:34:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3601680</guid><dc:creator>Simon C</dc:creator><description>&lt;p&gt;(Apologies for the gaps in my knowledge of the STL and its inner workings but...)&lt;/p&gt;
&lt;p&gt;If my solution uses a mixture of 3rd-party LIBs and/or OBJs which may well have been built with different values for _SECURE_SCL, how am I to workaround this mixture of _SECURE_SCL=0 and _SECURE_SCL=1?? &amp;nbsp;Do I need to wrap all 3rd-party objects in DLLs?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=3601680" width="1" height="1"&gt;</description></item><item><title>re: STL: Destructor of Bugs (std::deque)</title><link>http://blogs.msdn.com/b/vcblog/archive/2007/02/26/stl-destructor-of-bugs.aspx#2366862</link><pubDate>Wed, 02 May 2007 05:13:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2366862</guid><dc:creator>Stephen Hewitt</dc:creator><description>&lt;p&gt;QUOTE:&lt;/p&gt;
&lt;p&gt; First, I should mention that the swap bug has now been fixed in Orcas! The fix applies to all Standard containers except std::string. Additionally, std::deque was broken even when _SECURE_SCL was disabled; it has also been fixed.&lt;/p&gt;
&lt;p&gt;END QUOTE&lt;/p&gt;
&lt;p&gt;Regarding Orcas:&lt;/p&gt;
&lt;p&gt; I have to like with 2005. Can I gets fixed for that compiler?&lt;/p&gt;
&lt;p&gt;Regarding deques:&lt;/p&gt;
&lt;p&gt; You say the deque is broken even when _SECURE_SCL=0. Can you elaborate on this? Are you saying the deque is not usable if swap is called?&lt;/p&gt;
&lt;p&gt;Regarding Service Packs:&lt;/p&gt;
&lt;p&gt; Are any of there issues resolved by SPs? I've got SP1.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2366862" width="1" height="1"&gt;</description></item><item><title>re: STL: Destructor of Bugs</title><link>http://blogs.msdn.com/b/vcblog/archive/2007/02/26/stl-destructor-of-bugs.aspx#2042246</link><pubDate>Sat, 07 Apr 2007 00:41:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2042246</guid><dc:creator>michael henson</dc:creator><description>&lt;p&gt;Stephan - I noted your blog post regarding stl bugs, specifically _SECURE_SCL. &amp;nbsp;This note is more regarding your comment regarding compiling boost with _SECURE_SCL off. &amp;nbsp;I figured out how to do this since I was having the same compatability issues myself. &amp;nbsp;You can _SECURE_SCL off through editing this header:&lt;/p&gt;
&lt;p&gt;\boost_1_33_1\boost\config\compiler\visualc.hpp&lt;/p&gt;
&lt;p&gt;I just added the following to the start of the header.&lt;/p&gt;
&lt;p&gt;#ifdef _SECURE_SCL&lt;/p&gt;
&lt;p&gt;#undef _SECURE_SCL&lt;/p&gt;
&lt;p&gt;#endif&lt;/p&gt;
&lt;p&gt;#ifdef _HAS_ITERATOR_DEBUGGING&lt;/p&gt;
&lt;p&gt;#undef _HAS_ITERATOR_DEBUGGING&lt;/p&gt;
&lt;p&gt;#endif&lt;/p&gt;
&lt;p&gt;#define _SECURE_SCL 0&lt;/p&gt;
&lt;p&gt;#define _HAS_ITERATOR_DEBUGGING 0&lt;/p&gt;
&lt;p&gt;This suits my purpose, though I did get a few build errors in a few libraries that I'm not using. &amp;nbsp;Hope this was helpful. &amp;nbsp;Keep up the informative blogging!&lt;/p&gt;
&lt;p&gt;Michael Henson&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2042246" width="1" height="1"&gt;</description></item><item><title>re: STL: Destructor of Bugs</title><link>http://blogs.msdn.com/b/vcblog/archive/2007/02/26/stl-destructor-of-bugs.aspx#1848473</link><pubDate>Sat, 10 Mar 2007 03:01:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1848473</guid><dc:creator>Stephan T. Lavavej</dc:creator><description>&lt;p&gt;Yes, there are workarounds for the swap bug other than avoiding swapping or disabling _SECURE_SCL.&lt;/p&gt;
&lt;p&gt;(First, I should mention that the swap bug has now been fixed in Orcas! The fix applies to all Standard containers except std::string. Additionally, std::deque was broken even when _SECURE_SCL was disabled; it has also been fixed.)&lt;/p&gt;
&lt;p&gt;References and pointers don't trigger the problem, so using them is a workaround.&lt;/p&gt;
&lt;p&gt;Another workaround is translating iterators to indices and back (for the random-access sequences). That is, if you have an iterator into a vector or deque, figure out what index it points to (index = iter - cont.begin()), swap the containers, and then get an iterator from the index (iter = other.begin() + index).&lt;/p&gt;
&lt;p&gt;If you have further questions, feel free to E-mail me at stl@microsoft.com .&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
&lt;p&gt;Stephan T. Lavavej&lt;/p&gt;
&lt;p&gt;Visual C++ Libraries Developer&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1848473" width="1" height="1"&gt;</description></item><item><title>re: STL: Destructor of Bugs</title><link>http://blogs.msdn.com/b/vcblog/archive/2007/02/26/stl-destructor-of-bugs.aspx#1815684</link><pubDate>Tue, 06 Mar 2007 12:44:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1815684</guid><dc:creator>Michel</dc:creator><description>&lt;p&gt;Is there are work around to the _SECURE_SCL swap bug in release mode not involving recompiling the codebase including boost etc using _SECURE_SCL=0, and not rewriting your code not to swap containers?&lt;/p&gt;
&lt;p&gt;/Michel&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1815684" width="1" height="1"&gt;</description></item><item><title>VC++ Roundup</title><link>http://blogs.msdn.com/b/vcblog/archive/2007/02/26/stl-destructor-of-bugs.aspx#1793085</link><pubDate>Sat, 03 Mar 2007 08:13:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1793085</guid><dc:creator>RSS It All</dc:creator><description>&lt;p&gt;Lots of VC++ happening recently (in no particular order): ATL Server is now shared source Marina Polishchuk&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1793085" width="1" height="1"&gt;</description></item><item><title>VC++ Roundup</title><link>http://blogs.msdn.com/b/vcblog/archive/2007/02/26/stl-destructor-of-bugs.aspx#1792858</link><pubDate>Sat, 03 Mar 2007 07:33:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1792858</guid><dc:creator>ronpih's weblog</dc:creator><description>&lt;p&gt;Lots of VC++ happening recently (in no particular order): ATL Server is now shared source Marina Polishchuk&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1792858" width="1" height="1"&gt;</description></item><item><title>re: STL: Destructor of Bugs</title><link>http://blogs.msdn.com/b/vcblog/archive/2007/02/26/stl-destructor-of-bugs.aspx#1772326</link><pubDate>Wed, 28 Feb 2007 08:07:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1772326</guid><dc:creator>James Burgess</dc:creator><description>&lt;p&gt;Stephan,&lt;/p&gt;
&lt;p&gt; I would assume the linker just looks at the info in the .obj file (that the compiler flag /Zl controls) to determine which CRT's were specified at compile time. I'm going to take a wild guess that this mechanism isn't going to be extendable in any meanful way to solving the ODR problem. Too bad, seems like that was a special case of a set of ODR-like problems.&lt;/p&gt;
&lt;p&gt;Don't worry, I wasn't holding my breath for a fix :-) We'll be dealing with this for years.&lt;/p&gt;
&lt;p&gt;Too late now, but I would have preferred having yet another set of C++ runtimes to link against that would enforce (through undefined symbols) this flag one way or the other. That doesn't scale but nor does the notion of having switches that are quite this jagged and dangerous.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;- James&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1772326" width="1" height="1"&gt;</description></item><item><title>The One Definition Rule</title><link>http://blogs.msdn.com/b/vcblog/archive/2007/02/26/stl-destructor-of-bugs.aspx#1770641</link><pubDate>Wed, 28 Feb 2007 00:05:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1770641</guid><dc:creator>Stephan T. Lavavej</dc:creator><description>&lt;p&gt;James,&lt;/p&gt;
&lt;p&gt;That's not exactly a bug, but it certainly is a very sharp, jagged edge that you can cut yourself on.&lt;/p&gt;
&lt;p&gt;The general problem is that the linker does not diagnose all One Definition Rule (ODR) violations. Although not impossible, this is a difficult problem to solve, which is why the Standard specifically permits certain ODR violations to go undiagnosed. &lt;/p&gt;
&lt;p&gt;I would certainly love for the compiler and linker to have a special mode that would catch all ODR violations at build time, but I recognize that that would be difficult to achieve (and would consume resources that could perhaps be put to even better use, like more conformance). In any event, ODR violations can be avoided without extreme effort by properly structuring your code, so we as programmers can cope with this lack of linker checking.&lt;/p&gt;
&lt;p&gt;However, macros that change the functionality of code by being switched on and off are flirting dangerously with the ODR, and the specific problem is that _SECURE_SCL and _HAS_ITERATOR_DEBUGGING both do exactly this. At first glance, this might not seem so bad, since you should already have control over which macros are defined project-wide in your build system. However, separately compiled libraries complicate things - if you've built (for example) Boost with _SECURE_SCL on, which is the default, your project must not turn _SECURE_SCL off. If you're intent on turning _SECURE_SCL off in your project, now you have to re-build Boost accordingly. And depending on the separately compiled library in question, that might be difficult (with Boost, according to my understanding, it can be done, I've just never figured out how).&lt;/p&gt;
&lt;p&gt;What can we learn from this, other than (a) always remember the ODR, and (b) macros are evil (to quote the C++ FAQ Lite)? Well, I've observed something interesting: you are not supposed to mix object files compiled with different /MD, /MDd, /MT, /MTd options. But if you do, you get a LNK4098 warning! The linker has somehow been made to recognize this badness (since at least VC7.1, according to MSDN documentation). A casual glance at the source hasn't shown to me how this works, but it works somehow.&lt;/p&gt;
&lt;p&gt;To be clear, I cannot promise (and you should not expect) that anything will change here. However, I will think about how we trigger this LNK4098 warning, and whether something like that might also be applied to _SECURE_SCL and _HAS_ITERATOR_DEBUGGING, so that it would be harder for silent badness to occur.&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
&lt;p&gt;Stephan T. Lavavej&lt;/p&gt;
&lt;p&gt;Visual C++ Libraries Developer&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1770641" width="1" height="1"&gt;</description></item><item><title>re: STL: Destructor of Bugs</title><link>http://blogs.msdn.com/b/vcblog/archive/2007/02/26/stl-destructor-of-bugs.aspx#1770308</link><pubDate>Tue, 27 Feb 2007 22:23:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1770308</guid><dc:creator>James Burgess</dc:creator><description>&lt;p&gt;Stephan,&lt;/p&gt;
&lt;p&gt;Great that you are working on this. Speaking of catching errors early, one more &amp;quot;bug&amp;quot; I think the _SECURE_SCL code has is that it allows you to link an invalid set of compilation units together. That is you can link files compiled with and without _SECURE_SCL turned on. It would be nice if the linker forceably stopped you from making this mistake. The worst part is I have demonstrated it is possible the code that passes iterators between such units might run.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1770308" width="1" height="1"&gt;</description></item></channel></rss>