This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On Feb 1, 2005, at 11:55 AM, Mark Mitchell wrote:

Joe Buck wrote:
On Mon, Jan 31, 2005 at 05:52:24PM -0800, Mark Mitchell wrote:
It is not true that if GCC X accepted a piece of code, but GCC X + 1 does not, then we have removed a feature and must deprecate, etc.
In general this is true, but not in this case. You have removed a
well-known g++ extension that dates back to 1990, the first year that I
used g++.

I was using G++ at that point too, but I don't remember ever trying to do this particular thing. Perhaps I generally tried to avoid non-standard usage (in the ARM sense, in those days) more than other people using G++.


In any case, I suggest we hndle it as follows. The current codebase (as of this morning) will issue an error only with -pedantic. It will do that both for occurrences of floating-point literals in integral constant expressions (that are not cast to an integral type) and for initializations of static data members of floating-point type.

In other words, with -pedantic, we warn about both data members in:

  struct S {
    static const int i = 3.0; // Invalid integral constant expression.
    static const double d = 0; // Invalid data member type.
  };

With -fpermissive (or no option) we accept both lines.

So, I think the current codebase is acceptable to you.

This particular extension is very unlikely to cause us to do something really bad. (Other things that we used to accept in what should have been integral constant expressions did cause real confusion, including ICEs.) Also, I cannot think of any way in which allowing floating-point literals in integral constant expressions could change the meaning of a conforming program. So, the current state is acceptable to me too, except that instead of "if (pedantic) error (...)" I should probably use "if (pedantic) pedwarn (...)".

I think that the remaining action item, then, is to document this extension. Would you please document both the extension to allow floating-point literals in integral constant expressions and the extension to allow initialized static data members of floating-point type?

The documentation should presumably say that it's deprecated?


--Matt


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]