This is the mail archive of the gcc-bugs@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]

[Bug c++/11393] Initializer of static const float class member is not legal in c++98


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11393

--- Comment #19 from Manuel LÃpez-IbÃÃez <manu at gcc dot gnu.org> 2012-10-25 23:29:59 UTC ---
I think there are several issues conflated in this report. Perhaps the
following example is clearer:

class B { 
 static const int a = 1;     
 static const float b = 3;
 static const int c = 3.1415926;
};

Both -std=c++11 -pedantic and just -std=c++11 give:
error: âconstexprâ needed for in-class initialization of static data member
âconst float B::bâ of non-integral type [-fpermissive]
  static const float b = 3;
                         ^

-std=c++98 -pedantic gives
warning: ISO C++ forbids initialization of member constant âB::bâ of
non-integral type âconst floatâ [-Wpedantic]
  static const float b = 3;
                         ^
error: floating-point literal cannot appear in a constant-expression
  static const int c = 3.1415926;
                       ^

and -std=c++98 gives nothing.

Now, the first issue that Joseph discusses is that -std=, as currently
implemented, is not supposed to give all diagnostics required by the standard,
that is what -pedantic is for. Others disagree. Well, in this case, this issue
is moot, since the initialization of "b" is anyway a deprecated feature (and a
permerror in c++11), I would say: just make it a permerror also in c++98. Some
users may complain, but I think will make happy both Richard and Joseph.

The second bug I see here is that -pedantic creates a hard error for "c". This
is wrong. It is either a hard error all the time (with or without -pedantic) or
a permerror all the time, or it is a -pedantic warning that can be transformed
into an error by -pedantic-errors.

But there is probably even a third bug: are floating point literals accepted in
constant-expressions in c++11? If so, then the usual is to accept it in c++98
as an extension but warn with -pedantic (why reject something that is
implemented?). Otherwise, it should be rejected also in c++11.


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