Question about compiler bug: Value-initialization in new-expression
I recently got into trouble because MSVC++ appeared to incorrectly
implement value-initialization, for a struct that I was using. Luckily
the bug was reported in 2005 already, by Pavel: Feedback ID 100744,
"Value-initialization in new-expression".
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100744
The example has a struct that looks very much like mine:
struct A {
std::string s;
int i;
};
When doing "new A()", the int data member does not get zero-initialized,
as it should. Jonathan Caves (Visual C++ Compiler Team) has admitted
that it is indeed a bug.
Note that other attempts to value-initialize the struct fail as well:
#include <cassert>
class B {
A m_a;
public:
B(): m_a() {
assert(m_a.i == 0); // Assertion fails!
}
};
int main() {
A a1 = A();
assert(a1.i == 0); // Assertion fails!
A a2((A()));
assert(a2.i == 0); // Assertion fails!
B b;
return a1.i + a2.i;
}
This is a serious bug! Is it going to be solved with the next service
packs of VC++ 2003 and VC++ 2005? According to the Feedback page, the
status of #100744 is "Closed (Won't Fix)". Does that really mean that
this bug won't get fixed at all???
Kind regards,
--
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center