default constructors of __declspec(selecany) variables not called - by tobias.loew

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


1
0
Sign in
to vote
ID 652743 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 3/22/2011 1:07:57 AM
Access Restriction Public

Description

In the following example the constructor of stc_a is not called at startup, so the vtable is 0 and the program crashes at the call to foo() through a pointer to stc_a.
With stc_a_dummy (using the constructor with one argument) everything works fine.

///////////////////////////////////////////////////////////////////////////////

#include <tchar.h>

class a 
{
public:
    a()
    {}

    a(bool dummy)
    {}

    virtual void foo() const
    {}
};


__declspec( selectany ) extern const a stc_a;               // <-- not initialized at startup
__declspec( selectany ) extern const a stc_a_dummy(false);

int _tmain(int argc, _TCHAR* argv[])
{
    stc_a.foo();

    const a* ptr_a_dummy = &stc_a_dummy;
    ptr_a_dummy->foo();

    const a* ptr_a = &stc_a;
    ptr_a->foo();               //  <-- crash !

    return 0;
}

Sign in to post a comment.
Posted by Microsoft on 8/17/2011 at 11:20 AM
Hi: this issue has been fixed. The fix should show up in a future release of Visual C++.

Thank you for reporting the issue.

Jonathan Caves
Visual C++ Compiler Team
Posted by Microsoft on 3/22/2011 at 2:11 AM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by Microsoft on 3/22/2011 at 1:13 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)