This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG258d7b86eeab: [clang-format] Handle constructor invocations after new operator in C# correct (authored by eoanermine, committed by owenpan).
Changed prior to commit: https://reviews.llvm.org/D129926?vs=452513&id=462802#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129926/new/ 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 @@ -617,6 +617,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 @@ -2975,6 +2975,11 @@ if (Style.isCSharp()) { do { + // Handle constructor invocation, e.g. `new(field: value)`. + if (FormatTok->is(tok::l_paren)) + parseParens(); + + // Handle array initialization syntax, e.g. `new[] {10, 20, 30}`. if (FormatTok->is(tok::l_brace)) parseBracedList();
Index: clang/unittests/Format/FormatTestCSharp.cpp =================================================================== --- clang/unittests/Format/FormatTestCSharp.cpp +++ clang/unittests/Format/FormatTestCSharp.cpp @@ -617,6 +617,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 @@ -2975,6 +2975,11 @@ if (Style.isCSharp()) { do { + // Handle constructor invocation, e.g. `new(field: value)`. + if (FormatTok->is(tok::l_paren)) + parseParens(); + + // Handle array initialization syntax, e.g. `new[] {10, 20, 30}`. if (FormatTok->is(tok::l_brace)) parseBracedList();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits