[PATCH] D129926: [clang-format] Handle constructor invocations after new operator in C# correct
Danil Sidoruk via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 16 01:39:55 PDT 2022
eoanermine created this revision.
eoanermine added reviewers: owenpan, HazardyKnusperkeks, MyDeveloperDay.
eoanermine added projects: clang, clang-format.
Herald added a project: All.
eoanermine requested review of this revision.
Herald added a subscriber: cfe-commits.
- Handle constructor invocations after new operator in C# correct
- Add test for the case with lambda in constructor arguments after new operator
Closes https://github.com/llvm/llvm-project/issues/56549
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D129926
Files:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTestCSharp.cpp
Index: clang/unittests/Format/FormatTestCSharp.cpp
===================================================================
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -616,6 +616,24 @@
EXPECT_EQ(Code, format(Code, Style));
}
+TEST_F(FormatTestCSharp, CSharpNewOperator) {
+ FormatStyle Style = getLLVMStyle(FormatStyle::LK_CSharp);
+
+ verifyFormat("public void F() {\n"
+ " var v = new C(() => { var t = 5; });\n"
+ "}",
+ Style);
+ verifyFormat("public void F() {\n"
+ " var v = new C(() => {\n"
+ " try {\n"
+ " } catch {\n"
+ " var t = 5;\n"
+ " }\n"
+ " });\n"
+ "}",
+ Style);
+}
+
TEST_F(FormatTestCSharp, CSharpLambdas) {
FormatStyle GoogleStyle = getGoogleStyle(FormatStyle::LK_CSharp);
FormatStyle MicrosoftStyle = getMicrosoftStyle(FormatStyle::LK_CSharp);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2861,6 +2861,11 @@
if (Style.isCSharp()) {
do {
+ // Handle constructor invocation
+ if (FormatTok->is(tok::l_paren))
+ parseParens();
+
+ // Handle array initialization syntax
if (FormatTok->is(tok::l_brace))
parseBracedList();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129926.445207.patch
Type: text/x-patch
Size: 1495 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220716/077a9a0c/attachment.bin>
More information about the cfe-commits
mailing list