title: VC++: Code works in VS2010 and breaks in VS2013
body: <p>Edit: unlike the case in the question noted in the vote-to-close, the offending code here is CRT code, <em>not mine</em>. Even if it has a problem (which I'm pretty sure it doesn't), I have no way of fixing its source.</p>
  
  <hr>
  
  <p>We have some legacy memory-leak tracing code that uses some CRT internals (nothing too exotic, essentially _CrtMemBlockHeader which is <a href="http://msdn.microsoft.com/en-us/library/974tc9t1.aspx#BKMK_Find_buffer_overruns_with_debug_heap" rel="nofollow">sort-of documented</a>).  While trying to migrate from VS2010 to VS2013 the code seems to cause sporadic build failures, and the offending part can be reduced to this:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  
  #define _CRTBLD
  #include &lt;..\crt\src\dbgint.h&gt;
  
  #include &lt;fstream&gt;
  void Func()
  {
      std::ofstream myfile;
      myfile &lt;&lt; 8;
  }
  </code></pre>
  
  <p>I.e., these 10 lines alone builds fine in VS2010 and in VS2013 give:</p>
  
  <blockquote>
    <p>c:\program files (x86)\microsoft visual studio
    12.0\vc\include\xlocnum(1105): error C2491: 'std::numpunct&lt;_Elem>::id' : definition of dllimport static data member not allowed</p>
  </blockquote>
  
  <p>I suspect the error message is not accurate - there are indeed several potential definitions of id, none of them at line 1105.  There is also a considerable spew of warnings:</p>
  
  <pre><code>1&gt;c:\program files (x86)\microsoft visual studio 12.0\vc\include\xlocnum(1105): warning C4273: 'id' : inconsistent dll linkage
  1&gt;          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xlocnum(80) : see previous definition of 'public: static std::locale::id std::numpunct&lt;char&gt;::id'
  1&gt;          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xlocnum(80) : while compiling class template static data member 'std::locale::id std::numpunct&lt;_Elem&gt;::id'
  1&gt;          with
  1&gt;          [
  1&gt;              _Elem=char
  1&gt;          ]
  1&gt;          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xlocnum(1185) : see reference to function template instantiation 'const _Facet &amp;std::use_facet&lt;std::numpunct&lt;_Elem&gt;&gt;(const std::locale &amp;)' being compiled
  1&gt;          with
  1&gt;          [
  1&gt;              _Facet=std::numpunct&lt;char&gt;
  1&gt;  ,            _Elem=char
  1&gt;          ]
  1&gt;          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xlocnum(1179) : while compiling class template member function 'std::ostreambuf_iterator&lt;char,std::char_traits&lt;char&gt;&gt; std::num_put&lt;char,std::ostreambuf_iterator&lt;char,std::char_traits&lt;char&gt;&gt;&gt;::do_put(_OutIt,std::ios_base &amp;,_Elem,std::_Bool) const'
  1&gt;          with
  1&gt;          [
  1&gt;              _OutIt=std::ostreambuf_iterator&lt;char,std::char_traits&lt;char&gt;&gt;
  1&gt;  ,            _Elem=char
  1&gt;          ]
  1&gt;          c:\program files (x86)\microsoft visual studio 12.0\vc\include\ostream(306) : see reference to class template instantiation 'std::num_put&lt;char,std::ostreambuf_iterator&lt;char,std::char_traits&lt;char&gt;&gt;&gt;' being compiled
  1&gt;          c:\program files (x86)\microsoft visual studio 12.0\vc\include\ostream(292) : while compiling class template member function 'std::basic_ostream&lt;char,std::char_traits&lt;char&gt;&gt; &amp;std::basic_ostream&lt;char,std::char_traits&lt;char&gt;&gt;::operator &lt;&lt;(int)'
  1&gt;          c:\users\ofek\documents\visual studio 2013\projects\testcamsys2013\testcamsys2013\source.cpp(10) : see reference to function template instantiation 'std::basic_ostream&lt;char,std::char_traits&lt;char&gt;&gt; &amp;std::basic_ostream&lt;char,std::char_traits&lt;char&gt;&gt;::operator &lt;&lt;(int)' being compiled
  1&gt;          c:\program files (x86)\microsoft visual studio 12.0\vc\include\fstream(921) : see reference to class template instantiation 'std::basic_ostream&lt;char,std::char_traits&lt;char&gt;&gt;' being compiled
  1&gt;          c:\users\ofek\documents\visual studio 2013\projects\testcamsys2013\testcamsys2013\source.cpp(9) : see reference to class template instantiation 'std::basic_ofstream&lt;char,std::char_traits&lt;char&gt;&gt;' being compiled
  </code></pre>
  
  <p>For now I'm pasting the definitions of _CrtMemBlockHeader and some macros around it directly to my code.  But still - can anyone see what broke?   </p>
  
  <p>I realize it is not fully supported, but one can hope: is there a more robust way of using _CrtMemBlockHeader? </p>