This is the mail archive of the gcc-patches@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]

[C++ PATCH] [PR14028] Parser accepts invalid unbalanced bracket (regression 3.4/3.5)


Hello,

the parser accepts invalid code such as:
----------------------------------------------------------
template <int> struct A {};
template <typename TP> class B : public A<4  {};  // missing bracket!
----------------------------------------------------------

This happens because the check is done by cp_parser_require, which does not
emit an error during tentative parsing. The argument list is not invalidated by
this, and a CPP_TEMPLATE_ID is created, so that subsequent (non-tentative)
parsings fail to diagnose the problem. Fixed by forcing a hard error.

Tested on i686-pc-linux-gnu, OK for mainline and 3.4?

Giovanni Bajo


cp/
2003-02-05  Giovanni Bajo  <giovannibajo@gcc.gnu.org>

        PR c++/14028
        * parser.c (cp_parser_enclosed_template_argument_list): Emit straight
        error when terminator can nott be found.

testsuite/
2003-02-05  Giovanni Bajo  <giovannibajo@gcc.gnu.org>

        PR c++/14028
        * g++.dg/parse/angle-bracket2.C: New test.


Index: parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.166
diff -c -3 -p -r1.166 parser.c
*** parser.c 3 Feb 2004 16:53:24 -0000 1.166
--- parser.c 6 Feb 2004 04:18:07 -0000
*************** cp_parser_enclosed_template_argument_lis
*** 14463,14470 ****
     cp_lexer_consume_token (parser->lexer);
   }
      }
!   else
!     cp_parser_require (parser, CPP_GREATER, "`>'");
    /* The `>' token might be a greater-than operator again now.  */
    parser->greater_than_is_operator_p
      = saved_greater_than_is_operator_p;
--- 14537,14544 ----
     cp_lexer_consume_token (parser->lexer);
   }
      }
!   else if (!cp_parser_require (parser, CPP_GREATER, "`>'"))
!     error ("missing `>' to terminate the template argument list");
    /* The `>' token might be a greater-than operator again now.  */
    parser->greater_than_is_operator_p
      = saved_greater_than_is_operator_p;



// { dg-do compile }
// Contributed by MattyT <mattyt-bugzilla at tpg dot com dot au>
// PR c++/14028: Parser accepts invalid unbalanced bracket.

template <int> struct A {};
template <typename TP> class B : public A<4  {};    // { dg-error "" }



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