Note that there are some explanatory texts on larger screens.

plurals
  1. POreplacing new with macro conflicts with placement new
    primarykey
    data
    text
    <p>I've got a massive application (several million LOC, and tens of thousands of files), and I'm trying to use the debug crt to detect memory leaks. I'm trying to macro-ize new like so:</p> <pre><code>#define _CRTDBG_MAP_ALLOC #include &lt;crtdbg.h&gt; #ifndef NEW_DEBUG #define NEW_DEBUG new(_NORMAL_BLOCK, __FILE__, __LINE__) #define new NEW_DEBUG #endif </code></pre> <p>Now, my app is so big, so for me, ideally, I would put that in a header file and specifically include that in tens of thousands of CPP files. Not a fun task. So I've attempted to place this in a common header file in our SDK, which will get included in every translational unit. </p> <p>The problem I'm running into is it seems to clash with some STL header files, and the compiler emits errors when placement new is used. I can change that in my own code, by using pragma's and disabling the new macro. Not a problem there. It's the STL header files that use placement new, I can't change.</p> <p>I've figured out a <strong>work-around</strong>, by rearranging include directives in cpp files. For example:</p> <pre><code>// doesn't compile #include "new_redirect.h" #include &lt;map&gt; // for instance // does compile #include &lt;map&gt; // for instance #include "new_redirect.h" </code></pre> <p>But this is a difficult work-around because again, I have to go modify thousands of files, and make sure their STL headers are included <strong>before</strong> anything else. The ironic thing, is I created a hello world application to specifically test this problem: And the hello-world app of mine compiled fine. But my massive app doesn't, without this work-around.</p> <p>So my questions are:</p> <ol> <li>Has anyone been able to macro-ize new completely without jiggling massive amounts of code? (In a relatively painless way)</li> <li>Any other way to get around re-arranging my STL header include directives?</li> </ol> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload