Bug 24976 - [11/12/13/14 Regression] simple hexadecimal number and plus/minus and no space
Summary: [11/12/13/14 Regression] simple hexadecimal number and plus/minus and no space
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 4.0.3
: P5 minor
Target Milestone: 11.5
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2005-11-21 17:24 UTC by Bernardo Innocenti
Modified: 2023-07-07 10:28 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 2.95.3
Known to fail: 3.0.4, 4.0.4, 4.6.1, 4.6.3
Last reconfirmed: 2012-04-16 22:27:09


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bernardo Innocenti 2005-11-21 17:24:19 UTC
This testcase:

  int a = 0xe+100;

Produces a diagnostic message that would surprise
most users:

 foo.c:1:9: error: invalid suffix "+100" on integer constant


I'm not sure what the standard says about ambiguity
between the hex float notation and the regular + operator,
but many users are going to think of this behavior as
a parser bug.
Comment 1 Andrew Pinski 2005-11-21 17:28:33 UTC
(In reply to comment #0)
> but many users are going to think of this behavior as
> a parser bug.

This is more of a tokenizer error rather than a parser error.

Anyways 2.95.3 gives:
t.c:1: missing white space after number `0xe'

I wonder if we should accept this code for -std=c89.
Comment 2 jsm-csl@polyomino.org.uk 2005-11-21 18:21:48 UTC
Subject: Re:   New: simple hexadecimal number parsed as C99 hex
 float

On Mon, 21 Nov 2005, bernie at develer dot com wrote:

> This testcase:
> 
>   int a = 0xe+100;

0xe+100 is a single preprocessing number.  If the end of 
<http://gcc.gnu.org/onlinedocs/gcc/Incompatibilities.html> is unclear, 
please let us know how we could have improved it so that you would have 
realised it applies to this situation and so there is no bug.

Comment 3 Bernardo Innocenti 2005-11-21 18:41:15 UTC
(In reply to comment #2)

> 0xe+100 is a single preprocessing number.  If the end of 
> <http://gcc.gnu.org/onlinedocs/gcc/Incompatibilities.html> is unclear, 
> please let us know how we could have improved it so that you would have 
> realised it applies to this situation and so there is no bug.

We could handle it like we do for >> in nested template
declarations: split the token and try reparsing the
expression with the "other" meaning.  If it works, give
the friendly error message ("maybe you meant 0xe + 100?").
Comment 4 Andrew Pinski 2005-11-21 22:27:09 UTC
Confirmed, as a diagnostic issue only.  I am going to mark this as a regression even though I know that the preprocessor was rewritten between 2.95.3 and 3.0.x.
Comment 5 Mark Mitchell 2005-12-19 18:07:30 UTC
Downgraded to P5, as this will never be a release-critical issue.
Comment 6 Gabriel Dos Reis 2007-02-03 16:03:27 UTC
Won't fix in GCC-4.0.x.  Adjusting milestone.
Comment 7 Joseph S. Myers 2008-07-04 20:14:33 UTC
Closing 4.1 branch.
Comment 8 Joseph S. Myers 2009-03-31 19:01:30 UTC
Closing 4.2 branch.
Comment 9 Richard Biener 2009-08-04 12:27:19 UTC
GCC 4.3.4 is being released, adjusting target milestone.
Comment 10 Richard Biener 2010-05-22 18:10:47 UTC
GCC 4.3.5 is being released, adjusting target milestone.
Comment 11 Richard Biener 2011-06-27 12:12:21 UTC
4.3 branch is being closed, moving to 4.4.7 target.
Comment 12 Jakub Jelinek 2012-03-13 12:45:09 UTC
4.4 branch is being closed, moving to 4.5.4 target.
Comment 13 Bernie Innocenti 2012-04-16 04:24:58 UTC
Confirmed on gcc 4.6.3.
Comment 14 Jakub Jelinek 2013-04-12 15:15:42 UTC
GCC 4.6.4 has been released and the branch has been closed.
Comment 15 Richard Biener 2014-06-12 13:41:50 UTC
The 4.7 branch is being closed, moving target milestone to 4.8.4.
Comment 16 Jakub Jelinek 2014-12-19 13:24:58 UTC
GCC 4.8.4 has been released.
Comment 17 Richard Biener 2015-06-23 08:13:45 UTC
The gcc-4_8-branch is being closed, re-targeting regressions to 4.9.3.
Comment 18 Jakub Jelinek 2015-06-26 19:51:56 UTC
GCC 4.9.3 has been released.
Comment 19 Richard Biener 2016-08-03 10:40:09 UTC
GCC 4.9 branch is being closed
Comment 20 Jakub Jelinek 2018-10-26 10:18:28 UTC
GCC 6 branch is being closed
Comment 21 Richard Biener 2019-11-14 07:48:55 UTC
The GCC 7 branch is being closed, re-targeting to GCC 8.4.
Comment 22 Jakub Jelinek 2020-03-04 09:40:26 UTC
GCC 8.4.0 has been released, adjusting target milestone.
Comment 23 Jakub Jelinek 2021-05-14 09:45:39 UTC
GCC 8 branch is being closed.
Comment 24 Richard Biener 2021-06-01 08:04:13 UTC
GCC 9.4 is being released, retargeting bugs to GCC 9.5.
Comment 25 Richard Biener 2022-05-27 09:33:36 UTC
GCC 9 branch is being closed
Comment 26 Jakub Jelinek 2022-06-28 10:29:13 UTC
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
Comment 27 Andrew Pinski 2023-02-23 21:48:39 UTC
Something like this should improve the diagnostic, note the patch needs to be improved for wrapping:
diff --git a/libcpp/expr.cc b/libcpp/expr.cc
index 6e5bf68eae9..f70be382dd4 100644
--- a/libcpp/expr.cc
+++ b/libcpp/expr.cc
@@ -728,7 +728,7 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
          else
            {
              cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0,
-                                  "invalid suffix \"%.*s\" on floating constant",
+                                  "invalid suffix \"%.*s\" on floating constant (maybe missing a space)",
                                   (int) (limit - str), str);
              return CPP_N_INVALID;
            }
@@ -753,7 +753,7 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
       if ((result & CPP_N_DFLOAT) && radix != 10)
         {
           cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0,
-                              "invalid suffix \"%.*s\" with hexadecimal floating constant",
+                              "invalid suffix \"%.*s\" with hexadecimal floating constant (maybe missing a space)",
                               (int) (limit - str), str);
           return CPP_N_INVALID;
         }
@@ -789,7 +789,7 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
          else
            {
              cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0,
-                                  "invalid suffix \"%.*s\" on integer constant",
+                                  "invalid suffix \"%.*s\" on integer constant (maybe missing a space)",
                                   (int) (limit - str), str);
              return CPP_N_INVALID;
            }
Comment 28 Richard Biener 2023-07-07 10:28:41 UTC
GCC 10 branch is being closed.