G++ gives ICE on non-initialized static const member
Courtenay Footman
cpf@lightlink.com
Thu Feb 15 00:09:00 GMT 2001
I tried to use your GNATS website, but lynx does not work on it; --
the text fields are unmodifiable!
Courtenay Footman
cpf@lightlink.com
Summary g++ 2.95.2 gives ice on an array member sized by a static const member
Severity: non-critical
Priority: ???
Category: c++
Class: ice-on-legal-code
Release: GNU C++ version 2.95.2 19991024 (release)
Environment
machine: (i586-pc-linux-gnulibc1)
operating system: Red Hat Linux 5.0
Description:
If a const static variable is used as an array bound in a
derived class, g++ 2.95 gives an internal compiler error:
bug.i:14: Internal compiler error 19970302.
bug.i:14: Please submit a full bug report.
bug.i:14: See <URL: http://www.gnu.org/software/gcc/faq.html#bugreport > for instructions.
How-to-Repeat:
Compile the following code fragment with g++:
-----------------------------------------------------
class Base
{
int x;
public:
Base(const Base &);
};
class Derived : public Base
{
static const int N;
int y[N];
public:
Derived();
}; // Line 14
-----------------------------------------------------
Work Around:
Use global constants with funny names instead of member constants.
This is mildly disgusting. Alternatively, use the preprocessor, as
in old fashioned C, which is also mildly disgusting.
I am not one hundred percent certain that this is legal code, but it
should be. Correct code is produced (including code using sizeof (Derived))
if the ': public Base' is removed. (N has to be defined someplace, of
course: const int Derived::N = 4;)
(GCC 2.7 allowed variables like N to be initialized inside the class
declaration. In its infinite wisdom, ANSI C++ does not, and 2.95
enforces this. Changing previously working code to comply is how I
found the bug.)
--
Courtenay Footman I have again gotten back on the net, and
cpf@lightlink.com again I will never get anything done.
(All mail from non-valid addresses is automatically deleted by my system.)
More information about the Gcc-bugs
mailing list