This revision was automatically updated to reflect the committed changes. Closed by commit rG5c917bd9a7de: [clang-format] No space in `new()` and `this[Type x]` in C# (authored by Jonathan Coe <jb...@google.com>).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75984/new/ https://reviews.llvm.org/D75984 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTestCSharp.cpp Index: clang/unittests/Format/FormatTestCSharp.cpp =================================================================== --- clang/unittests/Format/FormatTestCSharp.cpp +++ clang/unittests/Format/FormatTestCSharp.cpp @@ -627,6 +627,8 @@ verifyFormat(R"(taskContext.Factory.Run(async () => doThing(args);)", Style); verifyFormat(R"(catch (TestException) when (innerFinallyExecuted))", Style); verifyFormat(R"(private float[,] Values;)", Style); + verifyFormat(R"(Result this[Index x] => Foo(x);)", Style); + verifyFormat(R"(class ItemFactory<T> where T : new() {})", Style); Style.SpacesInSquareBrackets = true; verifyFormat(R"(private float[ , ] Values;)", Style); Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -2930,6 +2930,14 @@ // interpolated strings. Interpolated strings are merged into a single token // so cannot have spaces inserted by this function. + // No space between 'this' and '[' + if (Left.is(tok::kw_this) && Right.is(tok::l_square)) + return false; + + // No space between 'new' and '(' + if (Left.is(tok::kw_new) && Right.is(tok::l_paren)) + return false; + // Space before { (including space within '{ {'). if (Right.is(tok::l_brace)) return true;
Index: clang/unittests/Format/FormatTestCSharp.cpp =================================================================== --- clang/unittests/Format/FormatTestCSharp.cpp +++ clang/unittests/Format/FormatTestCSharp.cpp @@ -627,6 +627,8 @@ verifyFormat(R"(taskContext.Factory.Run(async () => doThing(args);)", Style); verifyFormat(R"(catch (TestException) when (innerFinallyExecuted))", Style); verifyFormat(R"(private float[,] Values;)", Style); + verifyFormat(R"(Result this[Index x] => Foo(x);)", Style); + verifyFormat(R"(class ItemFactory<T> where T : new() {})", Style); Style.SpacesInSquareBrackets = true; verifyFormat(R"(private float[ , ] Values;)", Style); Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -2930,6 +2930,14 @@ // interpolated strings. Interpolated strings are merged into a single token // so cannot have spaces inserted by this function. + // No space between 'this' and '[' + if (Left.is(tok::kw_this) && Right.is(tok::l_square)) + return false; + + // No space between 'new' and '(' + if (Left.is(tok::kw_new) && Right.is(tok::l_paren)) + return false; + // Space before { (including space within '{ {'). if (Right.is(tok::l_brace)) return true;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits