On 31/07/19 21:16 +0200, Jakub Jelinek wrote:
On Wed, Jul 31, 2019 at 07:58:55PM +0100, Jonathan Wakely wrote:
> Perhaps add __extension__ before the literals too?
Does that do anything for Q literals? I thought I'd tried it
previously and decided it didn't. I'm happy to add it though.
You're right, it works well that way only in C, not in C++, on say:
long double x = 1.234Q;
long double y = __extension__ 1.234Q;
This is pedwarned not when actually parsing the number, but
when tokenizing it, which for C++ we do before parsing for all tokens.
We could add a hack for it, say don't emit the pedwarn if the previous token
is RID_EXTENSION, but it wouldn't be anything close to how we handle
__extension__ during parsing (where pedantic is disabled while parsing the
whole cast expression after it).
Ah yes, I definitely looked into this before.
If I use the Q suffix like so ...
#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
template<>
inline constexpr __float128 e_v<__float128>
= 2.718281828459045235360287471352662498Q;
...
#endif
Then it produces 13 pedwarns with -pedantic -Wsystem-headers:
In file included from num.cc:1:
/home/jwakely/gcc/10/include/c++/10.0.0/numbers:139:7: warning: non-standard
suffix on floating constant [-Wpedantic]
139 | = 2.718281828459045235360287471352662498Q;
| ^
Users would get those warnings even if not using the __float128
constants. Admittedly, if they use -pedantic combined with
-std=gnu++2a, and combine that with -Wsystem-headers, they deserve
what they get.
I think it's better to have accurate __float128 constants even if they
warn with certain combinations of warning flags.