Article View: gnu.g++.bug
Article #309Initialization bug?
From: John Shewchuk
Date: Mon, 31 Jul 1989 18:28
Date: Mon, 31 Jul 1989 18:28
54 lines
1871 bytes
1871 bytes
It appears that there is a bug in g++ that deals with static members and
initialization. The following file will not compile in g++ 1.35.1.
Regards,
John Shewchuk
// -*- C++ -*-
///////////////////////////////////////////////////////////////////////////
//
// Example that demonstrates an initialization problem with
// g++ version 1.35.1- (g++ -v).
//
// The line `static X instance_x;' generates:
//
// t.c:20: warning: member `instance_x' cannot be static
// (type `X' needs constructing)
//
// as well as several errors.
//
// According to Dan Weinreb <404@odi.ODI.COM> this works under cfront 2.0.
// Furthermore, he write:
// According to the Product Reference Manual, page 60, sec 9.4:
//
// "Static members obey the usual class member access rules, except that
// they can be initialized (in file scope)."
//
// Also see the C++ Primer.
///////////////////////////////////////////////////////////////////////////
class X {
private:
int x_value;
public:
X(int x) { x_value = x; } // The only constructor- note arg.
};
class Y {
private:
static X instance_x; // Must be initialized.
int y_value;
public:
Y(int y) { y_value = y; }
};
X Y::instance_x(1); // Initialization does not violate access rules.
main()
{
Y(2);
}
John Shewchuk jps@cs.brown.edu
Technical Details
Message-ID:
<11617@brunix.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!cs.utexas.edu!uunet!brunix!jpsShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!cs.utexas.edu!uunet!brunix!jps From: jps@cs.brown.edu (John Shewchuk) Newsgroups: gnu.g++.bug Subject: Initialization bug? Keywords: access, initialization, static members Message-ID: <11617@brunix.UUCP> Date: 31 Jul 89 18:28:24 GMT Sender: news@brunix.UUCP Reply-To: jps@cs.brown.edu (John Shewchuk) Organization: Brown Computer Science Lines: 54