Home Dashboard Directory Help
Search

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


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 652743
Opened: 3/22/2011 1:07:57 AM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

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;
}

Details
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)
Sign in to post a workaround.