Home Dashboard Directory Help
Search

const data member triggers dynamic initialization with C++ compiler by biochimia


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 716461
Opened: 1/4/2012 3:19:22 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

Below is a reduced test case exemplifying the issue.

    // main.cpp
    #include <assert.h>

    struct Data { int ref; };
    struct ConstData { const Data header; }; // < problematic const

    extern ConstData sharedNull;

    struct File {
        File() { assert(sharedNull.header.ref == -1); }
    };

    File global;
    ConstData sharedNull = { { -1 } };

    int main() {}

Removing the const in the commented line produces the expected results below, but I don't see why that should trigger zero-initialization followed by dynamic-initialization of the global sharedNull.

Changing the const-ness of the global sharedNull variable doesn't affect the results either way. The issue has also been reproduced in optimized builds.
Details
Sign in to post a comment.
Posted by Microsoft on 1/5/2012 at 2:37 PM
Hi: while I can reproduce this problem using the Dev10 compiler it appears that it has been fixed in current builds of the compiler. The fix should show up in a future release of Visual C++.

Thanks
Jonathan Caves
Visual C++ Compiler Team
Posted by MS-Moderator07 [Feedback Moderator] on 1/4/2012 at 9:43 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by MS-Moderator01 on 1/4/2012 at 3:42 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)
Posted by biochimia on 1/4/2012 at 3:20 AM
A vanilla installation of VS 2010 didn't show this issue, but subsequent updates, prior to SP1, do.
Sign in to post a workaround.