This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/21089] New: c++ accepts invalid static const double members with initializer
- From: "matz at suse dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 18 Apr 2005 17:26:20 -0000
- Subject: [Bug c++/21089] New: c++ accepts invalid static const double members with initializer
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
See this testcase:
-------------------------
struct Ball {
static const double diameter = 20;
void setPosition(double ,double );
double vect_Pos;
};
void move (double, double);
void Ball::setPosition(double xval,double yval) {
vect_Pos=xval;
move(xval-(diameter/2),yval-(diameter/2));
}
-------------------------
This is from kbilliard, and I only noticed the problem, because a reference
to Ball::diameter is left in the generated code, which can't be resolved,
as it's defined nowhere. Initially I was tricked by the java like syntax,
but then saw PR20098, according to which this is invalid code (for two
reasons). So it seems there are two problems:
1) missed optimization, as for instance if I remove the 'vectPos=xval' line
I get no linker error, and in fact in the dumps the references to
diameter are substituted by the defined value (double)20
2) the invalidness of the code is not diagnosed.
It's invalid for two reasons I think, first the missing definition, instead
of the declaration. But that can't be diagnosed except by the linker, which
indeed it does.
But when reading PR20098 I learned that static const members are only
allowed to have an initializer when they are of integral type. This is
not the case here. If the compiler would have diagnosed it, the root cause
of this problem had been more visible.
--
Summary: c++ accepts invalid static const double members with
initializer
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: matz at suse dot de
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21089