https://github.com/owenca created https://github.com/llvm/llvm-project/pull/125021
Fixes #124921. >From 1ca8ed5646429368412eba2e856d8215e3ded1a2 Mon Sep 17 00:00:00 2001 From: Owen Pan <owenpi...@gmail.com> Date: Wed, 29 Jan 2025 20:08:17 -0800 Subject: [PATCH] [clang-format] Fix a crash on parsing requires clause Fixes #124921. --- clang/lib/Format/UnwrappedLineParser.cpp | 2 +- clang/unittests/Format/FormatTest.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 906fc11a07d5ee..120922d271aab7 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -3632,7 +3632,7 @@ void UnwrappedLineParser::parseRequiresClause(FormatToken *RequiresToken) { // It could be inlined into here. parseConstraintExpression(); - if (!InRequiresExpression) + if (!InRequiresExpression && FormatTok->Previous) FormatTok->Previous->ClosesRequiresClause = true; } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 57f12221cdc7e6..30f3533ac73f72 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -26478,6 +26478,9 @@ TEST_F(FormatTest, RequiresClauses) { "foo();\n" "#endif\n" "bar(requires);"); + + verifyNoCrash("template <class T>\n" + " requires(requires { std::declval<T>()"); } TEST_F(FormatTest, RequiresExpressionIndentation) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits