public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113839] New: misleading syntax error message
@ 2024-02-08 19:02 f.heckenbach@fh-soft.de
  2024-02-08 19:05 ` [Bug c++/113839] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: f.heckenbach@fh-soft.de @ 2024-02-08 19:02 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113839
           Summary: misleading syntax error message
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: f.heckenbach@fh-soft.de
  Target Milestone: ---

% cat test.cpp
void f ()
{
  static int { };
}
% g++ test.cpp
test.cpp: In function 'void f()':
test.cpp:3:3: error: expected primary-expression before 'static'
    3 |   static int { };
      |   ^~~~~~

This message is clearly misleading. There is nothing missing before "static",
but rather the variable name after "int" is missing.

I seem to get a lot of such confusing messages, to the point I tend to ignore
the wording of the messages and treat them as generic "syntax error" messages,
which is sad.

While I appreciate gcc trying to by helpful, it seems it goes wrong rather
often. I'd prefer if gcc (by default, or at least optional) would limit itself
to reporting actual errors if and when they occur. (In this case, the program
is correct up to and including "static int", so there shouldn't be any error
reported on that part.)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/113839] misleading syntax error message
  2024-02-08 19:02 [Bug c++/113839] New: misleading syntax error message f.heckenbach@fh-soft.de
@ 2024-02-08 19:05 ` pinskia at gcc dot gnu.org
  2024-02-08 19:06 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-08 19:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> I'd prefer if gcc (by default, or at least optional) would limit itself to reporting actual errors if and when they occur.

Except C++ parsing does not allow for that because C++ parsing requires
unlimited look ahead.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/113839] misleading syntax error message
  2024-02-08 19:02 [Bug c++/113839] New: misleading syntax error message f.heckenbach@fh-soft.de
  2024-02-08 19:05 ` [Bug c++/113839] " pinskia at gcc dot gnu.org
@ 2024-02-08 19:06 ` mpolacek at gcc dot gnu.org
  2024-02-08 19:17 ` f.heckenbach@fh-soft.de
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-08 19:06 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-02-08
                 CC|                            |mpolacek at gcc dot gnu.org
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed; we should say that we expect an id there.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/113839] misleading syntax error message
  2024-02-08 19:02 [Bug c++/113839] New: misleading syntax error message f.heckenbach@fh-soft.de
  2024-02-08 19:05 ` [Bug c++/113839] " pinskia at gcc dot gnu.org
  2024-02-08 19:06 ` mpolacek at gcc dot gnu.org
@ 2024-02-08 19:17 ` f.heckenbach@fh-soft.de
  2024-02-08 20:22 ` redi at gcc dot gnu.org
  2024-02-08 20:29 ` redi at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: f.heckenbach@fh-soft.de @ 2024-02-08 19:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Frank Heckenbach <f.heckenbach@fh-soft.de> ---
> Except C++ parsing does not allow for that because C++ parsing requires
> unlimited look ahead.

While that's true in general, I think in specific cases (including most
real-world cases), the look-ahead required is limited. E.g., here, I think it's
clear the program is ill-formed at the ";" at the latest, perhaps even at the
"{}" already.

Even if gcc can't determine the cause of the error, I'd prefer if it said so
rather than chosing one (IMHO unlikely) candidate for correction. (Is there
actually a primary-expression that could be inserted there to make the program
correct, or would this only lead to the next error?)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/113839] misleading syntax error message
  2024-02-08 19:02 [Bug c++/113839] New: misleading syntax error message f.heckenbach@fh-soft.de
                   ` (2 preceding siblings ...)
  2024-02-08 19:17 ` f.heckenbach@fh-soft.de
@ 2024-02-08 20:22 ` redi at gcc dot gnu.org
  2024-02-08 20:29 ` redi at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2024-02-08 20:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #2)
> Confirmed; we should say that we expect an id there.

$ clang++ s.cc
s.cc:3:14: error: expected unqualified-id
  static int { };
             ^
1 error generated.

$ edg s.cc
"s.cc", line 3: error: expected an identifier
    static int { };
               ^

1 error detected in the compilation of "s.cc".

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/113839] misleading syntax error message
  2024-02-08 19:02 [Bug c++/113839] New: misleading syntax error message f.heckenbach@fh-soft.de
                   ` (3 preceding siblings ...)
  2024-02-08 20:22 ` redi at gcc dot gnu.org
@ 2024-02-08 20:29 ` redi at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2024-02-08 20:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Frank Heckenbach from comment #0)
> While I appreciate gcc trying to by helpful, it seems it goes wrong rather
> often.

That doesn't match my experience. The errors that mention a specific grammar
production tend to be accurate, with the odd exception like this bug (which
will get fixed).

I find the problem is that telling the user that a particular grammar
production (like "unqualified-id" or "primary-expression") is expected isn't
really helpful to the layperson who doesn't memorize the BNF-like grammar in
the standard. Clang tends to do a better job in that regard, balancing accuracy
with comprehensibility.

If you encounter cases where a diagnostic is misleading, wrong, or just
unhelpfully technical in its wording, please do report them so they can be
improved.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-02-08 20:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-08 19:02 [Bug c++/113839] New: misleading syntax error message f.heckenbach@fh-soft.de
2024-02-08 19:05 ` [Bug c++/113839] " pinskia at gcc dot gnu.org
2024-02-08 19:06 ` mpolacek at gcc dot gnu.org
2024-02-08 19:17 ` f.heckenbach@fh-soft.de
2024-02-08 20:22 ` redi at gcc dot gnu.org
2024-02-08 20:29 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).