[clang] 79210fe - [clang-format] Fix a crash on formatting missing r_paren/r_brace (#138230)
via cfe-commits
cfe-commits at lists.llvm.org
Fri May 2 19:20:45 PDT 2025
Author: Owen Pan
Date: 2025-05-02T19:20:42-07:00
New Revision: 79210feb2993ff9a79ef11f8a7016a527d4fcf22
URL: https://github.com/llvm/llvm-project/commit/79210feb2993ff9a79ef11f8a7016a527d4fcf22
DIFF: https://github.com/llvm/llvm-project/commit/79210feb2993ff9a79ef11f8a7016a527d4fcf22.diff
LOG: [clang-format] Fix a crash on formatting missing r_paren/r_brace (#138230)
Fix #138097
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 b67634c7f8ee0..ae33f4f6987ca 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1834,8 +1834,8 @@ void UnwrappedLineParser::parseStructuralElement(
nextToken();
if (FormatTok->is(tok::l_paren)) {
parseParens();
- assert(FormatTok->Previous);
- if (FormatTok->Previous->endsSequence(tok::r_paren, tok::kw_auto,
+ if (FormatTok->Previous &&
+ FormatTok->Previous->endsSequence(tok::r_paren, tok::kw_auto,
tok::l_paren)) {
Line->SeenDecltypeAuto = true;
}
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 049df57ab5725..f85e078696730 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -14259,6 +14259,8 @@ TEST_F(FormatTest, IncorrectCodeUnbalancedBraces) {
verifyNoCrash("struct Foo {\n"
" operator foo(bar\n"
"};");
+ verifyNoCrash("decltype( {\n"
+ " {");
}
TEST_F(FormatTest, IncorrectUnbalancedBracesInMacrosWithUnicode) {
More information about the cfe-commits
mailing list