This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/31904] fail to link to static const double
- From: "dennis0yang at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 12 May 2007 08:29:14 -0000
- Subject: [Bug c++/31904] fail to link to static const double
- References: <bug-31904-14536@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #3 from dennis0yang at gmail dot com 2007-05-12 09:29 -------
Subject: Re: fail to link to static const double
I understand that the standard only specifies that static const for
integral type can be assigned within the class. My point is that if gcc
decides to allow the extension of assigning static const double within
the class (good extension, I don't see why this is not in the
standard.), then it should allow me to link to it. Note the code works
if I change "y=-x" to "y= -1 * x", so it is clearly a bug.
I also tried your suggestion before submitting the bug report. It does
work. But I really do not want to create a .cpp file just to put that
one line in it, much prefer to leave everything in the .h file.
fang at csl dot cornell dot edu wrote:
> ------- Comment #1 from fang at csl dot cornell dot edu 2007-05-12 09:06 -------
> You need to define Base::x out of class in some translation unit, the in-class
> declaration alone isn't enough, though sometimes the compiler will elide the
> reference to it if its value is known (optimization).
>
> const double Base::x = 1.0;
>
>
>
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31904