[PATCH] D75336: [clang-format] Improve C# handling of spaces in square brackets

Jonathan B Coe via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 28 03:27:01 PST 2020


jbcoe created this revision.
jbcoe added reviewers: MyDeveloperDay, krasimir.
jbcoe added a project: clang-format.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75336

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
@@ -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.
 }
 
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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75336.247207.patch
Type: text/x-patch
Size: 1553 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200228/a59ae28d/attachment.bin>


More information about the cfe-commits mailing list