[clang] [clang-format] Fix a crash on parsing requires clause (PR #125021)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 29 20:12:41 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: Owen Pan (owenca)
<details>
<summary>Changes</summary>
Fixes #<!-- -->124921.
---
Full diff: https://github.com/llvm/llvm-project/pull/125021.diff
2 Files Affected:
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+1-1)
- (modified) clang/unittests/Format/FormatTest.cpp (+3)
``````````diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 906fc11a07d5ee9..120922d271aab74 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 57f12221cdc7e66..30f3533ac73f72f 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) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/125021
More information about the cfe-commits
mailing list