This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/28858] New: [4.0/4.1/4.2 regression] Algorithm to find the end of a template parameter list is flawed


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]