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 @@ -2893,6 +2893,10 @@ if (Left.is(TT_TemplateCloser) && Right.is(TT_StartOfName)) return true; + // space after comma in '[,]'. + if (Left.is(tok::comma) && Right.is(tok::r_square)) + return Style.SpacesInSquareBrackets; + // space between keywords and paren e.g. "using (" if (Right.is(tok::l_paren)) if (Left.isOneOf(tok::kw_using, Keywords.kw_async, Keywords.kw_when)) 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 @@ -595,6 +595,10 @@ verifyFormat(R"(bool[] xs = { true, true };)", Style); verifyFormat(R"(taskContext.Factory.Run(async () => doThing(args);)", Style); verifyFormat(R"(catch (TestException) when (innerFinallyExecuted))", Style); + verifyFormat(R"(private float[,] Values;)", Style); + + Style.SpacesInSquareBrackets = true; + verifyFormat(R"(private float[, ] Values;)", Style); } } // namespace format