Skip to content

Commit

Permalink
[clang] require arg list in type specifiers using template kw (llvm#9…
Browse files Browse the repository at this point in the history
…4674)

Require a template argument list after a name prefixed by the template
keyword in nested name specifiers. Addresses [CWG
96](https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#96)
which was superseded by
[P1787](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1787r6.html).

Followup to llvm#80801.
  • Loading branch information
evelez7 authored and lravenclaw committed Jul 3, 2024
1 parent 260efe2 commit 6fb95f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion clang/lib/Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2060,9 +2060,19 @@ bool Parser::TryAnnotateTypeOrScopeToken(
return true;
}

bool TemplateKWPresent = false;
if (Tok.is(tok::kw_template)) {
ConsumeToken();
TemplateKWPresent = true;
}

TypeResult Ty;
if (Tok.is(tok::identifier)) {
// FIXME: check whether the next token is '<', first!
if (TemplateKWPresent && NextToken().isNot(tok::less)) {
Diag(Tok.getLocation(),
diag::missing_template_arg_list_after_template_kw);
return true;
}
Ty = Actions.ActOnTypenameType(getCurScope(), TypenameLoc, SS,
*Tok.getIdentifierInfo(),
Tok.getLocation());
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Parser/cxx2a-concepts-requires-expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool r23 = requires { typename identity<T>::temp<T>; };
template<typename T>
bool r24 = requires {
typename identity<T>::template temp<T>;
typename identity<T>::template temp; // expected-error{{expected an identifier or template-id after '::'}}
typename identity<T>::template temp; // expected-error{{template argument list is expected after a name prefixed by the template keyword}}
};

bool r25 = requires { ; };
Expand Down

0 comments on commit 6fb95f6

Please sign in to comment.