public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/62137] New: Poor error recovery when parsing for-loops
@ 2014-08-14 16:07 manu at gcc dot gnu.org
  2021-09-28 10:34 ` [Bug c++/62137] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: manu at gcc dot gnu.org @ 2014-08-14 16:07 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 62137
           Summary: Poor error recovery when parsing for-loops
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: manu at gcc dot gnu.org

This has to be a common mistake:

manuel@gcc10:~$ cat parseerr.cc 
void foo(void)
{
  for (int k, k < 20; k++);
}

Yet we give a not very good diagnostic:

parseerr.cc:3:17: error: expected initializer before ‘<’ token
   for (int k, k < 20; k++);
                 ^
parseerr.cc:3:17: error: expected ‘;’ before ‘<’ token
parseerr.cc:3:17: error: expected primary-expression before ‘<’ token

My guess is that "k <20" is parsed as a declaration of type "int", when that
fails something goes wrong, and instead of backtracking to ",", the parser
tries to finish the declaration starting from k but finds "<" instead of ";".
The last error, well, who knows!

After seeing the first error, there are perhaps two better options:

* If we know we are in a loop header, backtrack to after consuming, assume we
have seen ";" and continue.
* If not, simply skip to next ";"
>From gcc-bugs-return-458468-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Aug 14 16:11:04 2014
Return-Path: <gcc-bugs-return-458468-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 13843 invoked by alias); 14 Aug 2014 16:11:04 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 13776 invoked by uid 48); 14 Aug 2014 16:10:58 -0000
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug bootstrap/62077] --with-build-config=bootstrap-lto fails
Date: Thu, 14 Aug 2014 16:11:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: bootstrap
X-Bugzilla-Version: lto
X-Bugzilla-Keywords: build, lto
X-Bugzilla-Severity: normal
X-Bugzilla-Who: pinskia at gcc dot gnu.org
X-Bugzilla-Status: ASSIGNED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-62077-4-iQWxr4T27n@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-62077-4@http.gcc.gnu.org/bugzilla/>
References: <bug-62077-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-08/txt/msg00965.txt.bz2
Content-length: 999

https://gcc.gnu.org/bugzilla/show_bug.cgi?idb077

--- Comment #36 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to rguenther@suse.de from comment #35)
> On Thu, 14 Aug 2014, venkataramanan.kumar at amd dot com wrote:
>
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?idb077
> >
> > --- Comment #34 from Venkataramanan <venkataramanan.kumar at amd dot com> ---
> > Richard, What I understand is that instead of using tune flags for garbage
> > collection, need to try and fix the object code differences?
>
> Yes, it points at real bugs.  OTOH fixing that may not be suitable
> for the release branches, neither is passing fixed values for GC
> parameters.  So I'm not quite sure what a suitable workaround is
> (well, make sure !defined ENABLE_GC_CHECKING && !defined
> ENABLE_GC_ALWAYS_COLLECT is consistent between stage1 and stage2
> for bootstrap-lto, that is, init_ggc_heuristics () is executed
> in the same way)

Or better yet recommend with LTO bootstrap, bootstrap4.


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

* [Bug c++/62137] Poor error recovery when parsing for-loops
  2014-08-14 16:07 [Bug c++/62137] New: Poor error recovery when parsing for-loops manu at gcc dot gnu.org
@ 2021-09-28 10:34 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-28 10:34 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2016-08-14 00:00:00         |2021-9-28

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note clang we get:
<source>:4:15: error: redefinition of 'k'
  for (int k, k < 20; k++);
              ^
<source>:4:12: note: previous definition is here
  for (int k, k < 20; k++);
           ^
<source>:4:17: error: expected ';' in 'for' statement specifier
  for (int k, k < 20; k++);
                ^
<source>:4:17: error: expected expression

I don't think this is better at all.

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

end of thread, other threads:[~2021-09-28 10:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-14 16:07 [Bug c++/62137] New: Poor error recovery when parsing for-loops manu at gcc dot gnu.org
2021-09-28 10:34 ` [Bug c++/62137] " pinskia 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).