[Bug c++/101232] Bad error message with stray semicolon in initializer

2024-07-29 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101232

--- Comment #10 from Jonathan Wakely  ---
Please send the v2 patch to gcc-patches for review, thanks!

[Bug c++/101232] Bad error message with stray semicolon in initializer

2024-07-18 Thread franek.witt at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101232

--- Comment #9 from Franciszek Witt  ---
I have implemented the improvement mentioned by Jason and also added the hint
about missing comma or operator.
This patch fails testsuite/g++.dg/parse/error59.C but it was intended to check
for ICE (see PR c++/84493) so I think it is fine to accept a different error
message?

[Bug c++/101232] Bad error message with stray semicolon in initializer

2024-07-18 Thread franek.witt at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101232

--- Comment #8 from Franciszek Witt  ---
Created attachment 58700
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58700=edit
[patchv2] improvements to the previous patch

[Bug c++/101232] Bad error message with stray semicolon in initializer

2024-07-09 Thread franek.witt at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101232

--- Comment #7 from Franciszek Witt  ---
I believe it might also be worth reporting that a comma or an operator is
likely missing in case the braces.require_close failed and the next token is
not ';' (this is just a heuristic, some better condition probably could be used
here). 
What do you think about this idea?

[Bug c++/101232] Bad error message with stray semicolon in initializer

2024-07-05 Thread jason at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101232

--- Comment #6 from Jason Merrill  ---
It seems like the problem is that cp_parser_braced_list doesn't check  whether
braces.require_close succeeded and compensate if it fails; in that case it
might make sense to cp_parser_skip_to_closing_brace and try again.

[Bug c++/101232] Bad error message with stray semicolon in initializer

2024-07-04 Thread franek.witt at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101232

Franciszek Witt  changed:

   What|Removed |Added

 CC||franek.witt at gmail dot com

--- Comment #5 from Franciszek Witt  ---
Hi, I am fwitt from IRC.

On https://godbolt.org/z/3PoW93YMs GCC without your patch gives the same
misleading error. With your patch, the primary error message is improved, but
GCC also generates an additional error message about the missing semicolon.

===
./bad.cpp: In function ‘void f(int, int)’:
./bad.cpp:8:9: error: expected ‘}’ before ‘j’
8 | j
  | ^
./bad.cpp:6:6: note: to match this ‘{’
6 | X{
  |  ^
./bad.cpp:7:10: error: expected ‘;’ before ‘j’
7 | i
  |  ^
  |  ;
8 | j
  | ~ 
./bad.cpp: At global scope:
./bad.cpp:10:1: error: expected declaration before ‘}’ token
   10 | }
  | ^
===

I would like to fix this. I've just started learning about the compiler
internals, so it will probably take some time. I will come back here and ask
for help in a few days if I encounter any difficulties.

BTW is the "expected declaration" message expected here?

[Bug c++/101232] Bad error message with stray semicolon in initializer

2024-07-03 Thread jason at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101232

Jason Merrill  changed:

   What|Removed |Added

 CC||jason at gcc dot gnu.org

--- Comment #4 from Jason Merrill  ---
Created attachment 58588
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58588=edit
simple patch

I was discussing this on IRC today with fwitt, and discussed moving up the
cp_parser_definitely for functional cast in cp_parser_postfix_expression, but
this is simpler.  I'm not sure if there are further improvements you all want
as well?  If so, feel free to take this and build on it.

[Bug c++/101232] Bad error message with stray semicolon in initializer

2024-07-03 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101232

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
 Ever confirmed|0   |1
   Last reconfirmed||2024-07-03

--- Comment #3 from Andrew Pinski  ---
Confirmed.

[Bug c++/101232] Bad error message with stray semicolon in initializer

2021-07-13 Thread tobi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101232

--- Comment #2 from Tobias Schlüter  ---
Here's another way to trigger this, inspired by my other PR101435
(https://godbolt.org/z/no6aEqvh3):
===
template
class X {
public:
U v;

using Scalar = U;
static constexpr auto Dim = dim;

explicit X(U x) : v(x) {}

template
X cast()
{
return X(T{v});
}
};

void f(int err) {
auto propertyHelper = [err](M&& fallback) -> M {
using FloatM = X;
FloatM v{0};
return err == 0 ? M{ v.template cast(); } :
fallback;
};
}
===
Which gives a comically wrong cascade of errors:
---
: In lambda function:
:23:28: error: expected primary-expression before '{' token
   23 | return err == 0 ? M{ v.template cast(); } :
fallback;
  |^
:23:28: error: expected ':' before '{' token
   23 | return err == 0 ? M{ v.template cast(); } :
fallback;
  |^
  |:
:23:28: error: expected primary-expression before '{' token
:23:28: error: expected ';' before '{' token
   23 | return err == 0 ? M{ v.template cast(); } :
fallback;
  |^
  |;
:23:71: error: expected primary-expression before ':' token
   23 | return err == 0 ? M{ v.template cast(); } :
fallback;
  |   ^
Compiler returned: 1
-

[Bug c++/101232] Bad error message with stray semicolon in initializer

2021-07-07 Thread tobi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101232

--- Comment #1 from Tobias Schlüter  ---
BTW an equivalent C example gives the proper error both with C and C++
https://godbolt.org/z/sWc67eWT8
=
struct X {
int a;
int b;
};

void f() {
struct X x = { 1, 2; };
}
=

: In function 'void f()':
:7:24: error: expected '}' before ';' token
7 | struct X x = { 1, 2; };
  |  ~ ^
: At global scope:
:8:1: error: expected declaration before '}' token
8 | }
  | ^