This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/28858] New: [4.0/4.1/4.2 regression] Algorithm to find the end of a template parameter list is flawed
- From: "reichelt at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 26 Aug 2006 20:55:25 -0000
- Subject: [Bug c++/28858] New: [4.0/4.1/4.2 regression] Algorithm to find the end of a template parameter list is flawed
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
If an error occurs in a template parameter list, the frontend
sometimes calls cp_parser_skip_until_found to find the ">" that
marks the end of the list. The algorithm used there has some flaws,
though:
1) It doesn't keep track of the nesting levels of "< ... >".
This results in bogus error messages when templates are used as default
parameters or when template template parameters are involved, e.g.:
template<TEMPLATE<int> class> struct A {};
yields:
bug.cc:1: error: 'TEMPLATE' has not been declared
bug.cc:1: error: expected `>' before '<' token
bug.cc:1: error: expected identifier before '>' token
bug.cc:1: error: expected unqualified-id before '>' token
2) It doesn't stop at ";", or "{", or "}".
(These tokens probably indicate the end of a declaration or the start of
a function/struct body which is not part of a template parameter list.)
Because of this large parts of the source might be skipped,
if one forgets the closing ">", again resulting in bogus errors, e.g.:
template<int N struct A;
bool i = 1 > 0;
int j = i;
yields:
bug.cc:1: error: expected `>' before 'struct'
bug.cc:2: error: expected unqualified-id before numeric constant
bug.cc:3: error: 'i' was not declared in this scope
Posting a patch soon.
--
Summary: [4.0/4.1/4.2 regression] Algorithm to find the end of a
template parameter list is flawed
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Keywords: error-recovery, diagnostic
Severity: normal
Priority: P3
Component: c++
AssignedTo: reichelt at gcc dot gnu dot org
ReportedBy: reichelt at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28858