C++ PATCH: Disallow floating-point literals in integral-constant expressions

Ranjit Mathew rmathew@gmail.com
Tue Feb 1 09:39:00 GMT 2005


[Removed libstdc++; Added java-patches.]


On Mon, 31 Jan 2005 22:21:14 -0800, Mark Mitchell <mark@codesourcery.com> wrote:
> Ranjit Mathew wrote:
> 
> >>>  static const jfloat DEFAULT_LOAD_FACTOR = 0x1.800000p-1f;
> >>
> >>Ugh.  That's invalid C++.
> >
> >
> > Then that should have been a different error, no? :-)
> > (But I'm curious - and an ignoramus - why is that invalid?)
> 
> See this morning's discussion on the GCC mailing list.

Thanks for the pointer.


> The code generate by gjavah is invalid on two counts: (1) you can't have
> an in-class initialization a static data member of non-integral type,
> and (2) even for a static data member with integral type, the
> initializer has to be an integral constant expression, which a
> floating-point literal is not.

I have created PR java/19738 for this issue.

In the interim, I find that the attached patch fixes
the issue for me and allows me to finish bootstrap.
It also does not introduce any regressions in the
testsuite.

It is "bogus" in the sense that it just disables
the initialisation for static final real fields for
CNI (and not JNI).

That said, I am not completely sure of the
mechanics of the original code either - the
final (const) field would have been initialised
by the "Java side" too - so why do we need
to initialise it in C++? I'm sure I'm missing
something...

Ranjit.

-- 
Ranjit Mathew      Email: rmathew AT gmail DOT com

Bangalore, INDIA.    Web: http://ranjitmathew.hostingzero.com/
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: gjavah.txt
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20050201/ac27f5b3/attachment.txt>


More information about the Gcc-patches mailing list