public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/21089] New: c++ accepts invalid static const double members with initializer
@ 2005-04-18 17:26 matz at suse dot de
  2005-04-18 17:53 ` [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double pinskia at gcc dot gnu dot org
                   ` (16 more replies)
  0 siblings, 17 replies; 30+ messages in thread
From: matz at suse dot de @ 2005-04-18 17:26 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2010-08-31 17:41 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-21089-183@http.gcc.gnu.org/bugzilla/>
2005-10-11  7:20 ` [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double mmitchel at gcc dot gnu dot org
2005-10-11 16:49 ` mmitchel at gcc dot gnu dot org
2005-10-11 16:58 ` sabre at nondot dot org
2005-10-11 17:00 ` mark at codesourcery dot com
2005-10-11 17:03 ` sabre at nondot dot org
2005-10-11 17:05 ` mark at codesourcery dot com
2005-10-11 17:10 ` sabre at nondot dot org
2005-10-11 17:15 ` sabre at nondot dot org
2005-10-11 20:58 ` cvs-commit at gcc dot gnu dot org
2005-10-11 20:59 ` cvs-commit at gcc dot gnu dot org
2005-10-11 21:05 ` mmitchel at gcc dot gnu dot org
2010-08-31 17:26 ` jason at gcc dot gnu dot org
2010-08-31 17:41 ` mmitchel at gcc dot gnu dot org
2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
2005-04-18 17:53 ` [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double pinskia at gcc dot gnu dot org
2005-04-18 17:59 ` matz at suse dot de
2005-04-18 18:04 ` pinskia at gcc dot gnu dot org
2005-04-18 18:06 ` pinskia at gcc dot gnu dot org
2005-04-18 18:19 ` pinskia at gcc dot gnu dot org
2005-04-18 18:34 ` pinskia at gcc dot gnu dot org
2005-04-18 18:41 ` sabre at nondot dot org
2005-04-18 19:36 ` schlie at comcast dot net
2005-04-21  5:03 ` mmitchel at gcc dot gnu dot org
2005-04-28  2:11 ` pinskia at gcc dot gnu dot org
2005-04-28  2:46 ` matz at suse dot de
2005-04-28  8:03 ` nathan at gcc dot gnu dot org
2005-04-28  9:24 ` matz at suse dot de
2005-05-02 14:21 ` pinskia at gcc dot gnu dot org
2005-07-08  1:42 ` mmitchel at gcc dot gnu dot org
2005-09-20 14:33 ` pinskia at gcc dot gnu dot org
2005-09-27 16:25 ` mmitchel at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).