diff options
| author | Richard Trieu <rtrieu@google.com> | 2019-05-01 23:33:49 +0000 |
|---|---|---|
| committer | Richard Trieu <rtrieu@google.com> | 2019-05-01 23:33:49 +0000 |
| commit | 2efd30571bcc53003376410d4221f7e4dd19f4c3 (patch) | |
| tree | ad55278aa328faa44cdcf75d0fef84918043ce82 /clang/lib | |
| parent | d5c04860c1aab8bf056ab743de5414f634df359f (diff) | |
| download | bcm5719-llvm-2efd30571bcc53003376410d4221f7e4dd19f4c3.tar.gz bcm5719-llvm-2efd30571bcc53003376410d4221f7e4dd19f4c3.zip | |
Consume unexpected "template" keywords after "using"
The parser was dealing with unexpected "template" keywords after "using"
keywords too late and putting the parser into the wrong state, which could
lead to a crash down the line. This change allows the parser to consume the
bad "template" keywords earlier, and continue parsing as if "template" was
never there to begin with for better error recovery.
llvm-svn: 359740
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Parse/ParseDeclCXX.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 7d2fcbd3e1b..c4fe23c60c3 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -474,6 +474,13 @@ Parser::ParseUsingDirectiveOrDeclaration(DeclaratorContext Context, return nullptr; } + // Consume unexpected 'template' keywords. + while (Tok.is(tok::kw_template)) { + SourceLocation TemplateLoc = ConsumeToken(); + Diag(TemplateLoc, diag::err_unexpected_template_after_using) + << FixItHint::CreateRemoval(TemplateLoc); + } + // 'using namespace' means this is a using-directive. if (Tok.is(tok::kw_namespace)) { // Template parameters are always an error here. @@ -2542,6 +2549,13 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, // Eat 'using'. SourceLocation UsingLoc = ConsumeToken(); + // Consume unexpected 'template' keywords. + while (Tok.is(tok::kw_template)) { + SourceLocation TemplateLoc = ConsumeToken(); + Diag(TemplateLoc, diag::err_unexpected_template_after_using) + << FixItHint::CreateRemoval(TemplateLoc); + } + if (Tok.is(tok::kw_namespace)) { Diag(UsingLoc, diag::err_using_namespace_in_class); SkipUntil(tok::semi, StopBeforeMatch); |

