[Bug c++/109356] Enhancement idea to provide clearer missing brace line number

2023-04-09 Thread jg at jguk dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109356

--- Comment #8 from Jonny Grant  ---
(In reply to Xi Ruoyao from comment #7)
> (In reply to Jonny Grant from comment #6)
> > Tried a few other compilers on godbolt. 
> > 
> > ICC gets the warning on line 6
> > https://godbolt.org/z/fYb9c8f61
> > 
> > nvc++ gives the warning on line 6 
> > https://godbolt.org/z/xvh67odzY
> > 
> > MSVC and Clang don't.
> 
> This is just blind luck.  All of these compilers attempt to "fix" the syntax
> error by adding "}" at line 8 (not line 6!) and produce further warnings. 
> It's just ICC and nvc++ report "excess elements in initializer" at the
> beginning of the initializer, while the other compilers report it at the end.
> 
> Strictly speaking all of them are false warnings as there is no excess
> elements in the initializer (according to the programmer's mind).  But the
> only thing the parser can do is guessing the programmer wanted a "}" at line
> 8.

ok, thank you for your further replies

[Bug c++/109356] Enhancement idea to provide clearer missing brace line number

2023-04-09 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109356

--- Comment #7 from Xi Ruoyao  ---
(In reply to Jonny Grant from comment #6)
> Tried a few other compilers on godbolt. 
> 
> ICC gets the warning on line 6
> https://godbolt.org/z/fYb9c8f61
> 
> nvc++ gives the warning on line 6 
> https://godbolt.org/z/xvh67odzY
> 
> MSVC and Clang don't.

This is just blind luck.  All of these compilers attempt to "fix" the syntax
error by adding "}" at line 8 (not line 6!) and produce further warnings.  It's
just ICC and nvc++ report "excess elements in initializer" at the beginning of
the initializer, while the other compilers report it at the end.

Strictly speaking all of them are false warnings as there is no excess elements
in the initializer (according to the programmer's mind).  But the only thing
the parser can do is guessing the programmer wanted a "}" at line 8.

[Bug c++/109356] Enhancement idea to provide clearer missing brace line number

2023-04-08 Thread jg at jguk dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109356

--- Comment #6 from Jonny Grant  ---

Tried a few other compilers on godbolt. 

ICC gets the warning on line 6
https://godbolt.org/z/fYb9c8f61

nvc++ gives the warning on line 6 
https://godbolt.org/z/xvh67odzY

MSVC and Clang don't.

[Bug c++/109356] Enhancement idea to provide clearer missing brace line number

2023-04-06 Thread jg at jguk dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109356

--- Comment #5 from Jonny Grant  ---
I see it is more complicated than I imagined. Thank you for looking into it.

[Bug c++/109356] Enhancement idea to provide clearer missing brace line number

2023-04-05 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109356

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 number
> of a missing comma problem.
> 
> 
> https://godbolt.org/z/asGhE3W17
> 
> 
> :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 make
the syntax correct.

The parser always keeps progressing unless it's sure there is a syntax error. 
Note that 

static const char * list[][2] =
{
{"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 the
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.

[Bug c++/109356] Enhancement idea to provide clearer missing brace line number

2023-04-04 Thread jg at jguk dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109356

--- Comment #3 from Jonny Grant  ---
A different example where GCC does a good job of indicating the line number of
a missing comma problem.


https://godbolt.org/z/asGhE3W17


: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"},
  | ^

[Bug c++/109356] Enhancement idea to provide clearer missing brace line number

2023-03-31 Thread jg at jguk dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109356

--- Comment #2 from Jonny Grant  ---
(In reply to Xi Ruoyao from comment #1)
> I believe attempting to doing so would result exponential time complexity.


Ah ok, I didn't realise it would be complex.

I don't know enough about the internals, I was just thinking it could use the
[2] to know that it had got 2 elements, and that } closing brace was needed
before the comma.

ie.
:5:10: error: expected '}' before ',' token
5 | {"E", "F",
  |  ^

Or I thought it could just count the number of braces, and when it got to the
3rd open brace {


ie.
:6:2: error: expected '}' before '{' token
5 | {"E", "F",
  | ^

[Bug c++/109356] Enhancement idea to provide clearer missing brace line number

2023-03-31 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109356

Xi Ruoyao  changed:

   What|Removed |Added

 CC||xry111 at gcc dot gnu.org

--- Comment #1 from Xi Ruoyao  ---
I believe attempting to doing so would result exponential time complexity.

[Bug c++/109356] Enhancement idea to provide clearer missing brace line number

2023-03-31 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109356

Jonathan Wakely  changed:

   What|Removed |Added

   Severity|normal  |enhancement
   Keywords||diagnostic