Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -2902,8 +2902,8 @@ 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)) + // spaces inside square brackets. + if (Left.is(tok::l_square) || Right.is(tok::r_square)) return Style.SpacesInSquareBrackets; // No space before ? in nullable types. Index: clang/unittests/Format/FormatTestCSharp.cpp =================================================================== --- clang/unittests/Format/FormatTestCSharp.cpp +++ clang/unittests/Format/FormatTestCSharp.cpp @@ -600,7 +600,7 @@ verifyFormat(R"(private float[,] Values;)", Style); Style.SpacesInSquareBrackets = true; - verifyFormat(R"(private float[, ] Values;)", Style); + verifyFormat(R"(private float[ , ] Values;)", Style); } TEST_F(FormatTestCSharp, CSharpNullableTypes) { @@ -608,11 +608,7 @@ Style.SpacesInSquareBrackets = false; verifyFormat(R"(public float? Value;)", Style); // no space before `?`. - - // Erroneous spaces in square brackets here will be tackled in a follow-up - // patch and are not addressed by setting - // `Style.SpacesInSquareBrackets = false;` - verifyFormat(R"(int?[] arr = new int?[ 10 ];)", + verifyFormat(R"(int?[] arr = new int?[10];)", Style); // An array of a nullable type. }