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();
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();
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits