This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

c++/2972: Uninitialized member variables are not default initialized



>Number:         2972
>Category:       c++
>Synopsis:       Uninitialized member variables are not default initialized
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Sun May 27 04:56:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Petter Reinholdtsen
>Release:        gcc-2.95.2
>Organization:
>Environment:
Debian GNU/Linux 2.2
>Description:
If I read clause 12.6.2, 8.5 and 3.9 correctly, all scalar
member variables shall be default initialized to 0 unless
there is an explicit initialization in the constructor. The attached source demonstrate the problem.  The behaviour
is the same for gcc 2.95.2 and gcc 3.0 (using the internet
test compiler.)

A workaround is to initialize all member variables
explicitly, adding ': i(), p()' to the ctor in the example.
>How-To-Repeat:
Compile and watch the assert() fail.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/x-c++src; name="gcc-member-init.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="gcc-member-init.cpp"

I2luY2x1ZGUgPGFzc2VydC5oPgojaW5jbHVkZSA8c3RkbGliLmg+CmNsYXNzIFRlc3QKewogIGlu
dCBpOyAgIC8vIFNob3VsZCBiZSBkZWZhdWx0ICg9IHplcm8pIGluaXRpYWxpemVkCiAgdm9pZCAq
cDsgLy8gU2hvdWxkIGJlIGRlZmF1bHQgKD0gemVybykgaW5pdGlhbGl6ZWQKcHVibGljOgogIFRl
c3QoKQogIHsKICAgIGFzc2VydCgwID09IGkpOwogICAgYXNzZXJ0KDAgPT0gcCk7CiAgfTsKICB2
b2lkICpvcGVyYXRvciBuZXcoc2l6ZV90IHNpemUpCiAgewogICAgY2hhciAqcHRyID0gKGNoYXIq
KW1hbGxvYyhzaXplKTsKICAgIC8vIE1ha2Ugc3VyZSB0aGUgb2JqZWN0IGlzbid0IHplcm8taW5p
dGlhbGl6ZWQgcGVyIGRlZmF1bHQKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgc2l6ZTsgaSsrKQog
ICAgICBwdHJbaV0gPSAweGZmOwogICAgcmV0dXJuIHB0cjsKICB9CgogIHZvaWQgb3BlcmF0b3Ig
ZGVsZXRlKHZvaWQgKnB0cikKICB7CiAgICBmcmVlKHB0cik7CiAgfQp9OwoKaW50Cm1haW4oKQp7
CiAgVGVzdCAqdGVzdCA9IG5ldyBUZXN0KCk7CiAgcmV0dXJuIDA7Cn0K


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]