[llvm-branch-commits] [clang] a7f00c8 - [clang-format] Fix a crash on parsing requires clause (#125021)
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Feb 13 18:38:43 PST 2025
Author: Owen Pan
Date: 2025-02-13T18:38:24-08:00
New Revision: a7f00c8ed8c20a006fd7e592e99f3ca7b725b07e
URL: https://github.com/llvm/llvm-project/commit/a7f00c8ed8c20a006fd7e592e99f3ca7b725b07e
DIFF: https://github.com/llvm/llvm-project/commit/a7f00c8ed8c20a006fd7e592e99f3ca7b725b07e.diff
LOG: [clang-format] Fix a crash on parsing requires clause (#125021)
Fixes #124921.
(cherry picked from commit 14178deab0334d9ce095ae7adce408868659faee)
Added:
Modified:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 906fc11a07d5e..120922d271aab 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 57f12221cdc7e..30f3533ac73f7 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) {
More information about the llvm-branch-commits
mailing list