[C++] Dependent static constant variables of class templates not initialized correctly - by CodingCat

Status : 

  By Design<br /><br />
		The product team believes this item works according to its intended design.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


3
0
Sign in
to vote
ID 668988 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 5/17/2011 3:35:59 PM
Access Restriction Public

Description

Initializing a static constant variable of a class template by copying from another static constant variable of another class template results in zero-initialization when the dependent constant variable is used before the constant variable to be copied has been used for the first time. Manually 'using' the latter before using the dependent one yields results as expected.

Minimal reproduction C++ code sample enclosed. Observed both with and without SP1.
Sign in to post a comment.
Posted by Microsoft on 12/1/2011 at 11:37 AM
Hi: this issue is, unfortunately, By-Design. In the C++ Standard section 3.6.2/p2 states:

"Definitions of explicitly specialized class template static data members have ordered initialization. Other class template static data members (i.e., implicitly or explicitly instantiated specializations) have unordered initialization."

So in C++ you cannot, in general, depend on the order of initialization of static data members of a class template.

Thanks
Jonathan Caves
Visual C++ Compiler Team
Posted by CodingCat on 8/2/2011 at 11:26 AM
Any updates on this issue?
Posted by MS-Moderator08 [Feedback Moderator] on 5/17/2011 at 7:53 PM
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.