From 071f870e7ff0a3d04f0d93852ff7c29b59111f78 Mon Sep 17 00:00:00 2001 From: Marek Kurdej Date: Tue, 22 Feb 2022 15:46:28 +0100 Subject: [PATCH] [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 --- clang/lib/Format/UnwrappedLineParser.cpp | 10 +++++++--- clang/unittests/Format/FormatTestJS.cpp | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 35465bf..e2cbcea 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -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: diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index d84533e..67df2d4 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -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" -- 2.7.4