diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3015,6 +3015,10 @@ if (Right.is(TT_CSharpNullConditionalLSquare)) return false; + // No space between consecutive commas '[,,]'. + if (Left.is(tok::comma) && Right.is(tok::comma)) + return false; + // Possible space inside `?[ 0 ]`. if (Left.is(TT_CSharpNullConditionalLSquare)) return Style.SpacesInSquareBrackets; diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -640,9 +640,12 @@ verifyFormat(R"(private float[,] Values;)", Style); verifyFormat(R"(Result this[Index x] => Foo(x);)", Style); + verifyFormat(R"(char[,,] rawCharArray = MakeCharacterGrid();)", Style); + Style.SpacesInSquareBrackets = true; verifyFormat(R"(private float[ , ] Values;)", Style); verifyFormat(R"(string dirPath = args?[ 0 ];)", Style); + verifyFormat(R"(char[ ,, ] rawCharArray = MakeCharacterGrid();)", Style); } TEST_F(FormatTestCSharp, CSharpNullableTypes) {