[PATCH] D115794: [clang-format] put non-empty catch block on one line with AllowShortBlocksOnASingleLine: Empty
MyDeveloperDay via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 15 15:07:13 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa94aab12a4e0: [clang-format] put non-empty catch block on one line with… (authored by MyDeveloperDay).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115794/new/
https://reviews.llvm.org/D115794
Files:
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/FormatTestCSharp.cpp
Index: clang/unittests/Format/FormatTestCSharp.cpp
===================================================================
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -1379,5 +1379,22 @@
Style);
}
+TEST_F(FormatTestCSharp, EmptyShortBlock) {
+ auto Style = getLLVMStyle();
+ Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Empty;
+
+ verifyFormat("try {\n"
+ " doA();\n"
+ "} catch (Exception e) {\n"
+ " e.printStackTrace();\n"
+ "}\n",
+ Style);
+
+ verifyFormat("try {\n"
+ " doA();\n"
+ "} catch (Exception e) {}\n",
+ Style);
+}
+
} // namespace format
} // end namespace clang
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -22858,6 +22858,23 @@
verifyFormat("co_return co_yield foo();");
}
+TEST_F(FormatTest, EmptyShortBlock) {
+ auto Style = getLLVMStyle();
+ Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Empty;
+
+ verifyFormat("try {\n"
+ " doA();\n"
+ "} catch (Exception &e) {\n"
+ " e.printStackTrace();\n"
+ "}\n",
+ Style);
+
+ verifyFormat("try {\n"
+ " doA();\n"
+ "} catch (Exception &e) {}\n",
+ Style);
+}
+
} // namespace
} // namespace format
} // namespace clang
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -584,6 +584,9 @@
Keywords.kw___except)) {
if (Style.AllowShortBlocksOnASingleLine == FormatStyle::SBS_Never)
return 0;
+ if (Style.AllowShortBlocksOnASingleLine == FormatStyle::SBS_Empty &&
+ !I[1]->First->is(tok::r_brace))
+ return 0;
// Don't merge when we can't except the case when
// the control statement block is empty
if (!Style.AllowShortIfStatementsOnASingleLine &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115794.394668.patch
Type: text/x-patch
Size: 2257 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211215/b2f4003f/attachment-0001.bin>
More information about the cfe-commits
mailing list