Skip to content

Commit

Permalink
[clang-format] Avoid parsing "requires" as a keyword in non-C++-like …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
mkurdej committed Feb 22, 2022
1 parent 2aaba44 commit 071f870
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions clang/lib/Format/UnwrappedLineParser.cpp
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions clang/unittests/Format/FormatTestJS.cpp
Expand Up @@ -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"
Expand Down

0 comments on commit 071f870

Please sign in to comment.