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

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 716461 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 1/4/2012 3:19:22 AM
Access Restriction Public
Moderator Decision Sent to Engineering Team for consideration

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.
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.