From bf5bcf2c15c50381ad84d1ac9bbb171c91188b56 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 26 Jun 2018 23:20:26 +0000 Subject: Diagnose missing 'template' keywords in more cases. We track when we see a name-shaped expression followed by a '<' token and parse the '<' as a comparison. Then: * if we see a token sequence that cannot possibly be an expression but can be a template argument (in particular, a type-id) that follows either a ',' or the '<', diagnose that the '<' was supposed to start a template argument list, and * if we see '>()', diagnose that the '<' was supposed to start a template argument list. This only changes the diagnostic for error cases, and in practice appears to catch the most common cases where a missing 'template' keyword leads to parse errors within a template. Differential Revision: https://reviews.llvm.org/D48571 llvm-svn: 335687 --- clang/lib/Parse/ParseCXXInlineMethods.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'clang/lib/Parse/ParseCXXInlineMethods.cpp') diff --git a/clang/lib/Parse/ParseCXXInlineMethods.cpp b/clang/lib/Parse/ParseCXXInlineMethods.cpp index bccf4239c1b..77f2dccfede 100644 --- a/clang/lib/Parse/ParseCXXInlineMethods.cpp +++ b/clang/lib/Parse/ParseCXXInlineMethods.cpp @@ -312,6 +312,8 @@ void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) { Actions.ActOnDelayedCXXMethodParameter(getCurScope(), Param); std::unique_ptr Toks = std::move(LM.DefaultArgs[I].Toks); if (Toks) { + ParenBraceBracketBalancer BalancerRAIIObj(*this); + // Mark the end of the default argument so that we know when to stop when // we parse it later on. Token LastDefaultArgToken = Toks->back(); @@ -384,6 +386,8 @@ void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) { // Parse a delayed exception-specification, if there is one. if (CachedTokens *Toks = LM.ExceptionSpecTokens) { + ParenBraceBracketBalancer BalancerRAIIObj(*this); + // Add the 'stop' token. Token LastExceptionSpecToken = Toks->back(); Token ExceptionSpecEnd; @@ -489,6 +493,8 @@ void Parser::ParseLexedMethodDef(LexedMethod &LM) { ++CurTemplateDepthTracker; } + ParenBraceBracketBalancer BalancerRAIIObj(*this); + assert(!LM.Toks.empty() && "Empty body!"); Token LastBodyToken = LM.Toks.back(); Token BodyEnd; @@ -609,6 +615,8 @@ void Parser::ParseLexedMemberInitializer(LateParsedMemberInitializer &MI) { if (!MI.Field || MI.Field->isInvalidDecl()) return; + ParenBraceBracketBalancer BalancerRAIIObj(*this); + // Append the current token at the end of the new token stream so that it // doesn't get lost. MI.Toks.push_back(Tok); -- cgit v1.2.3