[Bug c++/70529] Unhelpful diagnostic for hex float literals, inconsistent parsing

manu at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Apr 7 20:39:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70529

--- Comment #5 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
(In reply to joseph@codesourcery.com from comment #4)
> On Tue, 5 Apr 2016, manu at gcc dot gnu.org wrote:
> 
> > According to the manual, if an extension is not incompatible with the base
> > standard, it should not be disabled:
> 
> In general, this extension *is* incompatible with the base standard - 
> there are cases where a program is valid with both versions of pp-numbers, 
> but with different semantics.  See gcc.dg/c90-hexfloat-2.c, for example.

Oh, well, then current status makes sense.

> It should be possible to lex according to the selected standard, but track 
> that a pp-token could be a hex float together with the following two 
> pp-tokens (+ or - and the exponent with possible suffix) and then handle 
> things specially if that sequence of pp-tokens ends up getting converted 
> to tokens.

Perhaps something simpler like this could be enough to inform naive users like
me?

Index: expr.c
===================================================================
--- expr.c      (revision 233781)
+++ expr.c      (working copy)
@@ -568,11 +568,26 @@ cpp_classify_number (cpp_reader *pfile,
            {
              if (DIGIT_SEP (*str))
                SYNTAX_ERROR_AT (virtual_location,
                                 "digit separator adjacent to exponent");
              else
-               SYNTAX_ERROR_AT (virtual_location, "exponent has no digits");
+               {
+                 if (radix == 16 && !CPP_OPTION (pfile, extended_numbers))
+                   {
+                     const cpp_token *tok2 = cpp_get_token (parse_in);
+                     const cpp_token *tok3 = cpp_get_token (parse_in);
+                     if ((tok2 == CPP_MINUS || tok2 == CPP_PLUS) 
+                         && tok3  == CPP_NUMBER)
+                       {
+                         if (CPP_OPTION (pfile, cplusplus))
+                           SYNTAX_ERROR_AT (virtual_location, "hexadecimal
floating constant with signed exponent requires C99");
+                         else
+                           SYNTAX_ERROR_AT (virtual_location, "hexadecimal
floating constant with signed exponent requires C++1z");
+                       }
+                   }
+                   SYNTAX_ERROR_AT (virtual_location, "exponent has no
digits");
+               }
            }
          do
            {
              seen_digit_sep = DIGIT_SEP (*str);
              str++;



It would be better to say:

prog.cc:1:10: error: hexadecimal floating constant with signed exponent
requires C++1z
 auto d = 0x123p-2;
          ~~~~~~^~

but I have no idea how to create ranges dynamically in the new rich_loc world.


More information about the Gcc-bugs mailing list