diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/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. diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/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