This revision was automatically updated to reflect the committed changes.
Closed by commit rGdb41c0b357d5: [clang-format] PR35514 brace-init member
initializers in function-try-blocks… (authored by MyDeveloperDay).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93296/new/
https://reviews.llvm.org/D93296
Files:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2727,6 +2727,29 @@
" throw;\n"
" }\n"
"};\n");
+ verifyFormat("class A {\n"
+ " int a;\n"
+ " A() try : a(0), b{1} {\n"
+ " } catch (...) {\n"
+ " throw;\n"
+ " }\n"
+ "};\n");
+ verifyFormat("class A {\n"
+ " int a;\n"
+ " A() try : a(0), b{1}, c{2} {\n"
+ " } catch (...) {\n"
+ " throw;\n"
+ " }\n"
+ "};\n");
+ verifyFormat("class A {\n"
+ " int a;\n"
+ " A() try : a(0), b{1}, c{2} {\n"
+ " { // New scope.\n"
+ " }\n"
+ " } catch (...) {\n"
+ " throw;\n"
+ " }\n"
+ "};\n");
// Incomplete try-catch blocks.
verifyIncompleteFormat("try {} catch (");
@@ -7756,8 +7779,8 @@
verifyFormat("co_yield -1;");
verifyFormat("co_return -1;");
- // Check that * is not treated as a binary operator when we set
PointerAlignment
- // as PAS_Left after a keyword and not a declaration.
+ // Check that * is not treated as a binary operator when we set
+ // PointerAlignment as PAS_Left after a keyword and not a declaration.
FormatStyle PASLeftStyle = getLLVMStyle();
PASLeftStyle.PointerAlignment = FormatStyle::PAS_Left;
verifyFormat("co_return *a;", PASLeftStyle);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2050,6 +2050,13 @@
nextToken();
if (FormatTok->is(tok::l_paren))
parseParens();
+ if (FormatTok->Previous && FormatTok->Previous->is(tok::identifier) &&
+ FormatTok->is(tok::l_brace)) {
+ do {
+ nextToken();
+ } while (!FormatTok->is(tok::r_brace));
+ nextToken();
+ }
// In case identifiers were removed by clang-tidy, what might follow is
// multiple commas in sequence - after the first identifier.
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2727,6 +2727,29 @@
" throw;\n"
" }\n"
"};\n");
+ verifyFormat("class A {\n"
+ " int a;\n"
+ " A() try : a(0), b{1} {\n"
+ " } catch (...) {\n"
+ " throw;\n"
+ " }\n"
+ "};\n");
+ verifyFormat("class A {\n"
+ " int a;\n"
+ " A() try : a(0), b{1}, c{2} {\n"
+ " } catch (...) {\n"
+ " throw;\n"
+ " }\n"
+ "};\n");
+ verifyFormat("class A {\n"
+ " int a;\n"
+ " A() try : a(0), b{1}, c{2} {\n"
+ " { // New scope.\n"
+ " }\n"
+ " } catch (...) {\n"
+ " throw;\n"
+ " }\n"
+ "};\n");
// Incomplete try-catch blocks.
verifyIncompleteFormat("try {} catch (");
@@ -7756,8 +7779,8 @@
verifyFormat("co_yield -1;");
verifyFormat("co_return -1;");
- // Check that * is not treated as a binary operator when we set PointerAlignment
- // as PAS_Left after a keyword and not a declaration.
+ // Check that * is not treated as a binary operator when we set
+ // PointerAlignment as PAS_Left after a keyword and not a declaration.
FormatStyle PASLeftStyle = getLLVMStyle();
PASLeftStyle.PointerAlignment = FormatStyle::PAS_Left;
verifyFormat("co_return *a;", PASLeftStyle);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2050,6 +2050,13 @@
nextToken();
if (FormatTok->is(tok::l_paren))
parseParens();
+ if (FormatTok->Previous && FormatTok->Previous->is(tok::identifier) &&
+ FormatTok->is(tok::l_brace)) {
+ do {
+ nextToken();
+ } while (!FormatTok->is(tok::r_brace));
+ nextToken();
+ }
// In case identifiers were removed by clang-tidy, what might follow is
// multiple commas in sequence - after the first identifier.
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits