[clang] d82adf3 - Allow space after C-style cast in C# code

via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 19 07:42:59 PST 2020


Author: mydeveloperday
Date: 2020-01-19T15:41:40Z
New Revision: d82adf328fb556e1e6d318608b683824c8badf22

URL: https://github.com/llvm/llvm-project/commit/d82adf328fb556e1e6d318608b683824c8badf22
DIFF: https://github.com/llvm/llvm-project/commit/d82adf328fb556e1e6d318608b683824c8badf22.diff

LOG: Allow space after C-style cast in C# code

Reviewed By: MyDeveloperDay, krasimir

Patch By: jbcoe

Differential Revision: https://reviews.llvm.org/D72150

Added: 
    

Modified: 
    clang/lib/Format/TokenAnnotator.cpp
    clang/unittests/Format/FormatTestCSharp.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 21a2184bf1d8..a8f33e62f994 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1640,8 +1640,9 @@ class AnnotatingParser {
 
   /// 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.

diff  --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp
index d8311d269647..95b14d0f0aa4 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -374,5 +374,14 @@ TEST_F(FormatTestCSharp, CSharpSpaceBefore) {
                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


        


More information about the cfe-commits mailing list