[Bug c++/11393] Initializer of static const float class member is not legal in c++98
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Oct 26 01:12:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11393
--- Comment #25 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-10-26 01:12:24 UTC ---
(In reply to comment #19)
> 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.
The problem with that is the lack of a good alternative. In C++11 there's a
workaround: use constexpr, but if you can't use C++11 then the extension is
useful, so removing it from C++98 mode would cause unnecessary annoyance for
users.
(In reply to comment #23)
> Do you mean floating-point literals or in-class initializer for static data
> member of type 'const float'?
The latter, which is the subject of this PR.
> In any case, clang seems to implement the most sane behaviour, no?
>
> g++ should do exactly the same, that is, accept the code with a pedwarn about
> "b" (either enabled by default or conditional in -Wpedantic), and do not warn
> or give an error about "c".
No. "c" is not valid in C++98, just because clang doesn't diagnose it doesn't
mean GCC should copy that. Richard's original report is about accepting
non-standard code without complaint, let's not make that worse!
(In reply to comment #24)
> So, in g++ parlance, "b" and "d" is a pedwarn enabled by default, while "c" is
> a pedwarn in c++98 mode enabled by -Wpedantic and nothing in c++11 mode.
Which makes sense, because "c" is not valid C++98 but is valid C++11
I think referring to what's actually valid according to the standard is useful,
rather than inferring it from what other compilers do.
My suggestion would be do nothing and lose the PR. If you want a warning in
C++98 use -pedantic, which is consistent with other GNU extensions. In C++11
use constexpr.
Making "b" give a pedwarn enabled by default would make some sense, but
probably still annoy some users.
More information about the Gcc-bugs
mailing list