From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 080393858C54; Wed, 5 Apr 2023 09:22:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 080393858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680686577; bh=ACr6ZNju+Fa4b7FcFc5wYjk2EOW/6RDd6aXE3+bKoJ8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ppiauiLLFpLDb5pf8qjwQchqmAsI9bNL3hkZneetZx3mHQcK7e2bPGmszbTjFepjP +mBVUg1zy5+roJih7+eIaedrTRh7Dwl+n00EE2fPIuQ6mgW7oI6g3/cPU5xuQ5x+o1 3+JcdenJlkjrE+iFnFHvrwY/6II/k1CggEyvtf48= From: "xry111 at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109356] Enhancement idea to provide clearer missing brace line number Date: Wed, 05 Apr 2023 09:22:55 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: xry111 at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: WONTFIX X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: resolution bug_status Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109356 Xi Ruoyao changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |WONTFIX Status|UNCONFIRMED |RESOLVED --- Comment #4 from Xi Ruoyao --- (In reply to Jonny Grant from comment #3) > A different example where GCC does a good job of indicating the line numb= er > of a missing comma problem. >=20 >=20 > https://godbolt.org/z/asGhE3W17 >=20 >=20 > :6:5: error: expected '}' before '{' token > 6 | {"G", "H"}, > | ^ > :2:1: note: to match this '{' > 2 | { > | ^ > :6:5: error: expected ',' or ';' before '{' token > 6 | {"G", "H"}, > | ^ This is easy because the parser has to insert a comma here to correct the syntax. But for a missing } it can be added at one of multiple places to m= ake the syntax correct. The parser always keeps progressing unless it's sure there is a syntax erro= r.=20 Note that=20 static const char * list[][2] =3D { {"A", "B"}, {"C", "D"}, {"E", "F", {"G", "H"}, {"I", "J"} }}; is NOT a syntax error. It's a semantic error (violating a constraint) but = the parser does not know about semantics (i.e. the parser does not know what "[= 2]" means at all). So the parser cannot be sure about the syntax error until t= he last line. Mixing the semantic analysis into the parser is not acceptable because it's= not how a compiler is implemented. Make the parser try different locations and pass all possible syntax tree to the further passes is at least quadratic behavior and not acceptable. I'll say this WONTFIX. If someone knows how to do this in a rational way please reopen.=