Note that there are some explanatory texts on larger screens.

plurals
  1. POVisual Studio 2008 c++ conditional template inheritance bug?
    primarykey
    data
    text
    <p>I'm in the process of porting a C++/<a href="http://wtl.sourceforge.net/" rel="nofollow noreferrer">WTL</a> project from Visual Studio 2005 to VS 2008. One of the project configurations is a unit-testing build, which defines the preprocessor symbol UNIT_TEST.</p> <p>In order to get my WTL classes into my test harness, I made a <code>CFakeWindow</code> class that stubs all the CWindow methods. Then in my stdafx.h file, I do this right below the import of atlwin.h (which defines the CWindow class):</p> <pre><code>#ifdef UNIT_TEST #include "fakewindow.h" #define CWindow CFakeWindow #endif </code></pre> <p>My window classes then look like this:</p> <pre><code>class CAboutDialog : public CDialogImpl&lt; CAboutDialog, CWindow &gt; , public CDialogResize&lt; CAboutDialog &gt; { // class definition omitted... }; </code></pre> <p>This works great in VS 2005. The problem is that in VS 2008, the methods from the original CWindow class are getting called, instead of the CFakeWindow class. This of course causes the tests to fail, because <code>CWindow</code> is sprinkled with <code>ATLASSERT(::IsWindow(m_hWnd))</code>.</p> <p>When I step through the code in the debugger, I see that the CAboutDialog class is inheriting from <code>CDialogImpl&lt;CAboutDialog, CFakeWindow&gt;</code>. Yet when I call a method on <code>CAboutDialog</code> (e.g. <code>EndDialog(code)</code>), the <code>CWindow</code> method is getting called.</p> <p>Is this a bug in VS 2008, or was my conditional template inheritance technique an abomination that VS 2005 allowed but VS 2008 "fixed"? Is there a work-around, or do I need to consider a different technique to unit-test WTL classes? I really like this technique, because it lets me get WTL classes into a test harness without mucking about with the WTL library.</p> <p><strong>Edit</strong>: As noted in the response to Conal, below, the preprocessor output shows that my class is inheriting from CFakeWindow:</p> <pre><code>class CAboutDialog : public CDialogImpl&lt;CAboutDialog, CFakeWindow &gt; , public CDialogResize&lt; CAboutDialog &gt; ... </code></pre> <p>And as stated above, when I step through the code in the debugger, CAboutDialog is shown in the locals window as inheriting from CFakeWindow.</p> <p><strong>Edit 2</strong>: As per Conal's advice, I stepped through the disassembly, and the code is supposedly calling the CFakeWindow method, but the CWindow method is what is actually called.</p> <pre><code> if ( wID == IDCANCEL ) 00434898 movzx edx,word ptr [ebp+8] 0043489C cmp edx,2 0043489F jne CAboutDialog::OnCloseCmd+90h (4348B0h) { EndDialog( wID ) ; 004348A1 movzx eax,word ptr [ebp+8] 004348A5 push eax 004348A6 mov ecx,dword ptr [ebp-10h] 004348A9 call ATL::CDialogImpl&lt;CAboutDialog,ATL::CFakeWindow&gt;::EndDialog (40D102h) } else 004348AE jmp CAboutDialog::OnCloseCmd+9Ah (4348BAh) { EndDialog(IDOK); 004348B0 push 1 004348B2 mov ecx,dword ptr [ebp-10h] 004348B5 call ATL::CDialogImpl&lt;CAboutDialog,ATL::CFakeWindow&gt;::EndDialog (40D102h) </code></pre> <p>I'm starting to lean more toward a bug in the VC++ 2008 debugger.</p>
    singulars
    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.
    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