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]

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


Jason Merrill wrote:

On Fri, 6 Feb 2004 14:44:33 +0100, "Giovanni Bajo" <giovannibajo@libero.it> wrote:



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.



I'm not very familiar with this code, but it seems to me that giving a hard error during tentative parsing isn't right.

That was my original concern too.

Basically, we must have conceptually committed by this point if issuing the error message make sense.

The problem is that we don't have nested parser committment; either we're fully committed, or we're not. So, we might be sure that we're looking a template argument list, but not sure what larger construct contains that argument list.

That's implicit in the way that cp_parser_template_id compacts a stream of tokens into a CPP_TEMPLATE_ID token. So, Giovanni's patch should be safe, even though it's non-intuitive in this way.

--
Mark Mitchell
CodeSourcery, LLC
(916) 791-8304
mark@codesourcery.com


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