From: mydeveloperday Date: Sun, 19 Jan 2020 15:41:40 +0000 (+0000) Subject: Allow space after C-style cast in C# code X-Git-Tag: llvmorg-12-init~17482 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d82adf328fb556e1e6d318608b683824c8badf22;p=platform%2Fupstream%2Fllvm.git Allow space after C-style cast in C# code Reviewed By: MyDeveloperDay, krasimir Patch By: jbcoe Differential Revision: https://reviews.llvm.org/D72150 --- diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 21a2184..a8f33e6 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1640,8 +1640,9 @@ private: /// 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 d8311d2..95b14d0 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