aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format/UnwrappedLineParser.cpp
diff options
context:
space:
mode:
authorOwen Pan <owenpiano@gmail.com>2025-04-16 18:48:10 -0700
committerGitHub <noreply@github.com>2025-04-16 18:48:10 -0700
commit9bd0c8726a5e3fd4f76e84692bd920dfca7a8d7f (patch)
treeea720e364476bb401bb3df98ff3533f312a3674d /clang/lib/Format/UnwrappedLineParser.cpp
parent53eae22e228532fe3349890b6c7fc10b9c10dbee (diff)
downloadllvm-9bd0c8726a5e3fd4f76e84692bd920dfca7a8d7f.zip
llvm-9bd0c8726a5e3fd4f76e84692bd920dfca7a8d7f.tar.gz
llvm-9bd0c8726a5e3fd4f76e84692bd920dfca7a8d7f.tar.bz2
[clang-format] Fix a bug in BWACS_MultiLine (#135906)
Fix #51940
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 5fe65cb..b9430d4 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -135,7 +135,8 @@ public:
CompoundStatementIndenter(UnwrappedLineParser *Parser,
const FormatStyle &Style, unsigned &LineLevel)
: CompoundStatementIndenter(Parser, LineLevel,
- Style.BraceWrapping.AfterControlStatement,
+ Style.BraceWrapping.AfterControlStatement ==
+ FormatStyle::BWACS_Always,
Style.BraceWrapping.IndentBraces) {}
CompoundStatementIndenter(UnwrappedLineParser *Parser, unsigned &LineLevel,
bool WrapBrace, bool IndentBrace)
@@ -3067,7 +3068,7 @@ void UnwrappedLineParser::parseTryCatch() {
parseStructuralElement();
--Line->Level;
}
- while (true) {
+ for (bool SeenCatch = false;;) {
if (FormatTok->is(tok::at))
nextToken();
if (!(FormatTok->isOneOf(tok::kw_catch, Keywords.kw___except,
@@ -3077,6 +3078,8 @@ void UnwrappedLineParser::parseTryCatch() {
FormatTok->is(Keywords.kw_finally)))) {
break;
}
+ if (FormatTok->is(tok::kw_catch))
+ SeenCatch = true;
nextToken();
while (FormatTok->isNot(tok::l_brace)) {
if (FormatTok->is(tok::l_paren)) {
@@ -3090,6 +3093,10 @@ void UnwrappedLineParser::parseTryCatch() {
}
nextToken();
}
+ if (SeenCatch) {
+ FormatTok->setFinalizedType(TT_ControlStatementLBrace);
+ SeenCatch = false;
+ }
NeedsUnwrappedLine = false;
Line->MustBeDeclaration = false;
CompoundStatementIndenter Indenter(this, Style, Line->Level);