Skip to content

Commit 6fb95f6

Browse files
evelez7lravenclaw
authored andcommitted
[clang] require arg list in type specifiers using template kw (llvm#94674)
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.
1 parent 260efe2 commit 6fb95f6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

clang/lib/Parse/Parser.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2060,9 +2060,19 @@ bool Parser::TryAnnotateTypeOrScopeToken(
20602060
return true;
20612061
}
20622062

2063+
bool TemplateKWPresent = false;
2064+
if (Tok.is(tok::kw_template)) {
2065+
ConsumeToken();
2066+
TemplateKWPresent = true;
2067+
}
2068+
20632069
TypeResult Ty;
20642070
if (Tok.is(tok::identifier)) {
2065-
// FIXME: check whether the next token is '<', first!
2071+
if (TemplateKWPresent && NextToken().isNot(tok::less)) {
2072+
Diag(Tok.getLocation(),
2073+
diag::missing_template_arg_list_after_template_kw);
2074+
return true;
2075+
}
20662076
Ty = Actions.ActOnTypenameType(getCurScope(), TypenameLoc, SS,
20672077
*Tok.getIdentifierInfo(),
20682078
Tok.getLocation());

clang/test/Parser/cxx2a-concepts-requires-expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ bool r23 = requires { typename identity<T>::temp<T>; };
8383
template<typename T>
8484
bool r24 = requires {
8585
typename identity<T>::template temp<T>;
86-
typename identity<T>::template temp; // expected-error{{expected an identifier or template-id after '::'}}
86+
typename identity<T>::template temp; // expected-error{{template argument list is expected after a name prefixed by the template keyword}}
8787
};
8888

8989
bool r25 = requires { ; };

0 commit comments

Comments
 (0)