File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -2050,6 +2050,13 @@ void UnwrappedLineParser::parseTryCatch() {
2050
2050
nextToken ();
2051
2051
if (FormatTok->is (tok::l_paren))
2052
2052
parseParens ();
2053
+ if (FormatTok->Previous && FormatTok->Previous ->is (tok::identifier) &&
2054
+ FormatTok->is (tok::l_brace)) {
2055
+ do {
2056
+ nextToken ();
2057
+ } while (!FormatTok->is (tok::r_brace));
2058
+ nextToken ();
2059
+ }
2053
2060
2054
2061
// In case identifiers were removed by clang-tidy, what might follow is
2055
2062
// multiple commas in sequence - after the first identifier.
Original file line number Diff line number Diff line change @@ -2727,6 +2727,29 @@ TEST_F(FormatTest, FormatTryCatch) {
2727
2727
" throw;\n"
2728
2728
" }\n"
2729
2729
"};\n");
2730
+ verifyFormat("class A {\n"
2731
+ " int a;\n"
2732
+ " A() try : a(0), b{1} {\n"
2733
+ " } catch (...) {\n"
2734
+ " throw;\n"
2735
+ " }\n"
2736
+ "};\n");
2737
+ verifyFormat("class A {\n"
2738
+ " int a;\n"
2739
+ " A() try : a(0), b{1}, c{2} {\n"
2740
+ " } catch (...) {\n"
2741
+ " throw;\n"
2742
+ " }\n"
2743
+ "};\n");
2744
+ verifyFormat("class A {\n"
2745
+ " int a;\n"
2746
+ " A() try : a(0), b{1}, c{2} {\n"
2747
+ " { // New scope.\n"
2748
+ " }\n"
2749
+ " } catch (...) {\n"
2750
+ " throw;\n"
2751
+ " }\n"
2752
+ "};\n");
2730
2753
2731
2754
// Incomplete try-catch blocks.
2732
2755
verifyIncompleteFormat("try {} catch (");
@@ -7756,8 +7779,8 @@ TEST_F(FormatTest, UnderstandsUnaryOperators) {
7756
7779
verifyFormat("co_yield -1;");
7757
7780
verifyFormat("co_return -1;");
7758
7781
7759
- // Check that * is not treated as a binary operator when we set PointerAlignment
7760
- // as PAS_Left after a keyword and not a declaration.
7782
+ // Check that * is not treated as a binary operator when we set
7783
+ // PointerAlignment as PAS_Left after a keyword and not a declaration.
7761
7784
FormatStyle PASLeftStyle = getLLVMStyle();
7762
7785
PASLeftStyle.PointerAlignment = FormatStyle::PAS_Left;
7763
7786
verifyFormat("co_return *a;", PASLeftStyle);
You can’t perform that action at this time.
0 commit comments