[PATCH] D72150: Allow space after C-style cast in C# code

Jonathan B Coe via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 3 06:27:45 PST 2020


jbcoe created this revision.
jbcoe added a reviewer: klimek.
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/D72150

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
@@ -374,5 +374,14 @@
                Style);
 }
 
+TEST_F(FormatTestCSharp, CSharpSpaceAfterCStyleCast) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+  
+  verifyFormat("(int)x / y;", Style);
+  
+  Style.SpaceAfterCStyleCast = true; 
+  verifyFormat("(int) x / y;", Style);
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1640,8 +1640,9 @@
 
   /// Determine whether ')' is ending a cast.
   bool rParenEndsCast(const FormatToken &Tok) {
-    // C-style casts are only used in C++ and Java.
-    if (!Style.isCpp() && Style.Language != FormatStyle::LK_Java)
+    // C-style casts are only used in C++, C# and Java.
+    if (!Style.isCSharp() && !Style.isCpp() && 
+        Style.Language != FormatStyle::LK_Java)
       return false;
 
     // Empty parens aren't casts and there are no casts at the end of the line.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72150.236048.patch
Type: text/x-patch
Size: 1254 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200103/01b4a422/attachment-0001.bin>


More information about the cfe-commits mailing list