[clang-format] Avoid parsing "requires" as a keyword in non-C++-like languages.

Fixes the issue raised post-review in D113319 (cf. https://reviews.llvm.org/D113319#3337485).

Reviewed By: krasimir

Differential Revision: https://reviews.llvm.org/D120324
This commit is contained in:
Marek Kurdej 2022-02-22 15:46:28 +01:00
parent 2aaba44b5c
commit 071f870e7f
2 changed files with 8 additions and 3 deletions

View File

@ -1563,9 +1563,13 @@ void UnwrappedLineParser::parseStructuralElement(IfStmtKind *IfKind,
parseConcept();
return;
case tok::kw_requires: {
bool ParsedClause = parseRequires();
if (ParsedClause)
return;
if (Style.isCpp()) {
bool ParsedClause = parseRequires();
if (ParsedClause)
return;
} else {
nextToken();
}
break;
}
case tok::kw_enum:

View File

@ -323,6 +323,7 @@ TEST_F(FormatTestJS, ReservedWords) {
verifyFormat("var struct = 2;");
verifyFormat("var union = 2;");
verifyFormat("var interface = 2;");
verifyFormat("var requires = {};");
verifyFormat("interface = 2;");
verifyFormat("x = interface instanceof y;");
verifyFormat("interface Test {\n"