Article View: gnu.g++.bug
Article #130data member initialization wrongly accepted
From: Doug Moore
Date: Thu, 09 Apr 1992 19:26
Date: Thu, 09 Apr 1992 19:26
36 lines
1532 bytes
1532 bytes
The following code:
====================
class foo
{
public:
int a = 0;
};
foo baz;
====================
not compile under Sun C++, with the error message:
====================
CC test.cc:
"test.cc", line 2: error: initializer for member a
1 error
====================
Looking through my C++ reference books, I cannot find anything to
indicate what the compiler should do with an attempt to initialize a
class data member within the class definition. Nor can I find a
mention of this as a gnu extension in the documentation that
accompanies gcc 2.1. Yet both g++ 1.40.3 and g++ 2.1 accept such
initializations without complaint.
Since my students attempt such initializations all the time and,
worse, sometimes the initializations achieve what the student
intended, I'd appreciate it if an upcoming version of GNU C++ flagged
this as an error.
BTW: The failure to warn occurs under GNU GCC 2.1, w/ Tiemann inf.
loop patches, and patches from Mike Stump for the Sabre detected bugs,
running on a SUN sparc2 running Sunos 4.1. The same behavior occurred
under g++ 1.40.3.
Doug Moore
(dougm@cs.rice.edu)
Technical Details
Message-ID:
<9204091926.AA03439@cs.rice.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.rice.edu!dougmShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.rice.edu!dougm From: dougm@cs.rice.edu (Doug Moore) Subject: data member initialization wrongly accepted Message-ID: <9204091926.AA03439@cs.rice.edu> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Thu, 9 Apr 1992 19:26:10 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 37