Skip to content

Commit a7f00c8

Browse files
owencatstellar
authored andcommitted
[clang-format] Fix a crash on parsing requires clause (llvm#125021)
Fixes llvm#124921. (cherry picked from commit 14178de)
1 parent 8215069 commit a7f00c8

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3632,7 +3632,7 @@ void UnwrappedLineParser::parseRequiresClause(FormatToken *RequiresToken) {
36323632
// It could be inlined into here.
36333633
parseConstraintExpression();
36343634

3635-
if (!InRequiresExpression)
3635+
if (!InRequiresExpression && FormatTok->Previous)
36363636
FormatTok->Previous->ClosesRequiresClause = true;
36373637
}
36383638

clang/unittests/Format/FormatTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26478,6 +26478,9 @@ TEST_F(FormatTest, RequiresClauses) {
2647826478
"foo();\n"
2647926479
"#endif\n"
2648026480
"bar(requires);");
26481+
26482+
verifyNoCrash("template <class T>\n"
26483+
" requires(requires { std::declval<T>()");
2648126484
}
2648226485

2648326486
TEST_F(FormatTest, RequiresExpressionIndentation) {

0 commit comments

Comments
 (0)