Bug 87713 - single character underlined in an error message instead of the whole token
Summary: single character underlined in an error message instead of the whole token
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.0
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, error-recovery
Depends on:
Blocks:
 
Reported: 2018-10-23 18:50 UTC by Martin Sebor
Modified: 2024-04-04 22:24 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-04-04 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2018-10-23 18:50:33 UTC
Every now and then I notice a diagnostic where only a single character of a token (identifier?) is underlined but up until now I haven't had luck reproducing it (often times it involves macros).  The ill-formed C++ test case below shows one situation when this happens without macros.  Note the underlining in the second error.

$ cat t.C && gcc -S  -Wall t.C
int i = sizeof ((int));
t.C:1:18: error: expected primary-expression before ‘int’
    1 | int i = sizeof ((int));
      |                  ^~~
t.C:1:18: error: expected ‘)’ before ‘int’
    1 | int i = sizeof ((int));
      |                 ~^~~
      |                  )
t.C:1:23: error: expected ‘)’ before ‘;’ token
    1 | int i = sizeof ((int));
      |                ~      ^
      |                       )

Other C++ compilers as well as GCC's C front end handle this more gracefully.  They print just a single message along the lines of:

t.C:1:22: error: expected expression before ‘)’ token
Comment 1 Martin Sebor 2018-10-23 18:51:46 UTC
David, you might be interested in this.
Comment 2 Andrew Pinski 2024-04-04 22:24:09 UTC
Confirmed.