Thread View: gnu.g++.bug
1 messages
1 total messages
Started by John Shewchuk
Mon, 31 Jul 1989 18:28
Initialization bug?
Author: 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads