https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61719
Bug ID: 61719
Summary: misleading error message
Product: gcc
Version: 4.10.0
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: drepper.fsp+rhbz at gmail dot com
This happens with older versions as well and the problem is worse in more
complicated situations. This is the boiled-down version. Take this source:
struct c {
c(int a) : aa(a {}
int aa;
};
c v(1);
There clearly is a type in the constructor call, the closing parenthesis is
missing. This causes the scanner to read the remainder of the file looking for
the end of the initializer of the call. The error messages you get are:
u.cc: In constructor ‘c::c(int)’:
u.cc:2:14: error: class ‘c’ does not have any field named ‘aa’
c(int a) : aa(a {}
^
u.cc:2:19: error: expected ‘)’ before ‘{’ token
c(int a) : aa(a {}
^
u.cc:3:7: error: expected ‘{’ at end of input
int aa;
^
Yes, the second error points in the right direction but in more complicated
situations there can be even more messages between the first message and the
one in second place here.
It seems that despite an error token being returned when looking for the end of
the initializer for aa the compiler first performs a lookup of the member which
of course makes no sense in this case since the remainder of the class is not
parsed.
I think something better can be done, maybe just skip looking up the member to
be initialized if there is a syntax error in the initializer call itself.