forked from OSchip/llvm-project
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
This commit is contained in:
parent
d5c04860c1
commit
2efd30571b
|
@ -683,6 +683,8 @@ def err_id_after_template_in_nested_name_spec : Error<
|
|||
"expected template name after 'template' keyword in nested name specifier">;
|
||||
def err_unexpected_template_in_unqualified_id : Error<
|
||||
"'template' keyword not permitted here">;
|
||||
def err_unexpected_template_after_using : Error<
|
||||
"'template' keyword not permitted after 'using' keyword">;
|
||||
def err_two_right_angle_brackets_need_space : Error<
|
||||
"a space is required between consecutive right angle brackets (use '> >')">;
|
||||
def err_right_angle_bracket_equal_needs_space : Error<
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
// RUN: %clang_cc1 %s -verify
|
||||
|
||||
namespace N1 {
|
||||
template <typename... Ts>
|
||||
struct Foo {
|
||||
template <typename T>
|
||||
struct Bar {
|
||||
static constexpr bool is_present = false;
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T, typename... Ts>
|
||||
struct Foo<T, Ts...> : public Foo<Ts...> {
|
||||
using template Foo<Ts...>::Bar;
|
||||
// expected-error@-1 {{'template' keyword not permitted after 'using' keyword}}
|
||||
};
|
||||
}
|
||||
|
||||
namespace N2 {
|
||||
namespace foo {
|
||||
using I = int;
|
||||
}
|
||||
using template namespace foo;
|
||||
// expected-error@-1 {{'template' keyword not permitted after 'using' keyword}}
|
||||
using template template namespace foo;
|
||||
// expected-error@-1 2{{'template' keyword not permitted after 'using' keyword}}
|
||||
I i;
|
||||
}
|
||||
|
||||
namespace N3 {
|
||||
namespace foo {
|
||||
using I = int;
|
||||
}
|
||||
using template foo::I;
|
||||
// expected-error@-1 {{'template' keyword not permitted after 'using' keyword}}
|
||||
I i;
|
||||
}
|
||||
|
||||
namespace N4 {
|
||||
template <typename T>
|
||||
class A {};
|
||||
|
||||
template <typename T>
|
||||
using B = A<T>;
|
||||
B<int> b;
|
||||
|
||||
using template <typename T> C = A<T>;
|
||||
// expected-error@-1 {{'template' keyword not permitted after 'using' keyword}}
|
||||
// expected-error@-2 {{expected unqualified-id}}
|
||||
C<int> c;
|
||||
// expected-error@-1 {{no template named 'C'}}
|
||||
}
|
Loading…
Reference in New Issue