[PATCH] D71769: [clang-format] C# formatting a class with inheritance followed by an attribute specifier assume its a braces initializer
This revision was automatically updated to reflect the committed changes. Closed by commit rG2f209ccfbe5e: [clang-format] C# formatting a class with inheritance followed by an attributeā¦ (authored by MyDeveloperDay). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D71769/new/ https://reviews.llvm.org/D71769 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 @@ -316,6 +316,27 @@ "}\n" "}\n", Style); + + verifyFormat("public A : Base\n" + "{\n" + "}\n" + "[Test]\n" + "public Foo()\n" + "{\n" + "}\n", + Style); + + verifyFormat("namespace\n" + "{\n" + "public A : Base\n" + "{\n" + "}\n" + "[Test]\n" + "public Foo()\n" + "{\n" + "}\n" + "}\n", + Style); } TEST_F(FormatTestCSharp, CSharpSpaceBefore) { Index: clang/lib/Format/UnwrappedLineParser.cpp === --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -466,7 +466,7 @@ (NextTok->is(tok::semi) && (!ExpectClassBody || LBraceStack.size() != 1)) || (NextTok->isBinaryOperator() && !NextIsObjCMethod); - if (NextTok->is(tok::l_square)) { + if (!Style.isCSharp() && NextTok->is(tok::l_square)) { // We can have an array subscript after a braced init // list, but C++11 attributes are expected after blocks. NextTok = Tokens->getNextToken(); Index: clang/unittests/Format/FormatTestCSharp.cpp === --- clang/unittests/Format/FormatTestCSharp.cpp +++ clang/unittests/Format/FormatTestCSharp.cpp @@ -316,6 +316,27 @@ "}\n" "}\n", Style); + + verifyFormat("public A : Base\n" + "{\n" + "}\n" + "[Test]\n" + "public Foo()\n" + "{\n" + "}\n", + Style); + + verifyFormat("namespace\n" + "{\n" + "public A : Base\n" + "{\n" + "}\n" + "[Test]\n" + "public Foo()\n" + "{\n" + "}\n" + "}\n", + Style); } TEST_F(FormatTestCSharp, CSharpSpaceBefore) { Index: clang/lib/Format/UnwrappedLineParser.cpp === --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -466,7 +466,7 @@ (NextTok->is(tok::semi) && (!ExpectClassBody || LBraceStack.size() != 1)) || (NextTok->isBinaryOperator() && !NextIsObjCMethod); - if (NextTok->is(tok::l_square)) { + if (!Style.isCSharp() && NextTok->is(tok::l_square)) { // We can have an array subscript after a braced init // list, but C++11 attributes are expected after blocks. NextTok = Tokens->getNextToken(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D71769: [clang-format] C# formatting a class with inheritance followed by an attribute specifier assume its a braces initializer
mitchell-stellar accepted this revision. mitchell-stellar added a comment. This revision is now accepted and ready to land. LGTM Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D71769/new/ https://reviews.llvm.org/D71769 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D71769: [clang-format] C# formatting a class with inheritance followed by an attribute specifier assume its a braces initializer
MyDeveloperDay created this revision. MyDeveloperDay added reviewers: mitchell-stellar, klimek, sammccall. MyDeveloperDay added a project: clang-format. Herald added a project: clang. MyDeveloperDay edited the summary of this revision. https://bugs.llvm.org/show_bug.cgi?id=44340 The rule that prevents `... {} [[]]` being treated as a braced initializer for C++ causes problems for C# with attributes, causing it to be incorrectly classified and then messing up the subsequent formatting. (see bug for details of formatting) Repository: rC Clang https://reviews.llvm.org/D71769 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 @@ -316,6 +316,27 @@ "}\n" "}\n", Style); + + verifyFormat("public A : Base\n" + "{\n" + "}\n" + "[Test]\n" + "public Foo()\n" + "{\n" + "}\n", + Style); + + verifyFormat("namespace\n" + "{\n" + "public A : Base\n" + "{\n" + "}\n" + "[Test]\n" + "public Foo()\n" + "{\n" + "}\n" + "}\n", + Style); } TEST_F(FormatTestCSharp, CSharpSpaceBefore) { Index: clang/lib/Format/UnwrappedLineParser.cpp === --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -466,7 +466,7 @@ (NextTok->is(tok::semi) && (!ExpectClassBody || LBraceStack.size() != 1)) || (NextTok->isBinaryOperator() && !NextIsObjCMethod); - if (NextTok->is(tok::l_square)) { + if (!Style.isCSharp() && NextTok->is(tok::l_square)) { // We can have an array subscript after a braced init // list, but C++11 attributes are expected after blocks. NextTok = Tokens->getNextToken(); Index: clang/unittests/Format/FormatTestCSharp.cpp === --- clang/unittests/Format/FormatTestCSharp.cpp +++ clang/unittests/Format/FormatTestCSharp.cpp @@ -316,6 +316,27 @@ "}\n" "}\n", Style); + + verifyFormat("public A : Base\n" + "{\n" + "}\n" + "[Test]\n" + "public Foo()\n" + "{\n" + "}\n", + Style); + + verifyFormat("namespace\n" + "{\n" + "public A : Base\n" + "{\n" + "}\n" + "[Test]\n" + "public Foo()\n" + "{\n" + "}\n" + "}\n", + Style); } TEST_F(FormatTestCSharp, CSharpSpaceBefore) { Index: clang/lib/Format/UnwrappedLineParser.cpp === --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -466,7 +466,7 @@ (NextTok->is(tok::semi) && (!ExpectClassBody || LBraceStack.size() != 1)) || (NextTok->isBinaryOperator() && !NextIsObjCMethod); - if (NextTok->is(tok::l_square)) { + if (!Style.isCSharp() && NextTok->is(tok::l_square)) { // We can have an array subscript after a braced init // list, but C++11 attributes are expected after blocks. NextTok = Tokens->getNextToken(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits