diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -593,9 +593,10 @@ FormatToken *RecordTok = Line.First; // Skip record modifiers. while (RecordTok->Next && - RecordTok->isOneOf(tok::kw_typedef, tok::kw_export, - Keywords.kw_declare, Keywords.kw_abstract, - tok::kw_default)) + RecordTok->isOneOf( + tok::kw_typedef, tok::kw_export, Keywords.kw_declare, + Keywords.kw_abstract, tok::kw_default, tok::kw_public, + tok::kw_private, tok::kw_protected, Keywords.kw_internal)) RecordTok = RecordTok->Next; if (RecordTok && RecordTok->isOneOf(tok::kw_class, tok::kw_union, tok::kw_struct, 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 @@ -70,6 +70,30 @@ " f();\n" " }\n" "}"); + + // Ensure that small and empty classes are handled correctly with condensed + // (Google C++-like) brace-breaking style. + FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp); + Style.BreakBeforeBraces = FormatStyle::BS_Attach; + + verifyFormat("public class SomeEmptyClass {}", Style); + + verifyFormat("public class SomeTinyClass {\n" + " int X;\n" + "}", + Style); + verifyFormat("private class SomeTinyClass {\n" + " int X;\n" + "}", + Style); + verifyFormat("protected class SomeTinyClass {\n" + " int X;\n" + "}", + Style); + verifyFormat("internal class SomeTinyClass {\n" + " int X;\n" + "}", + Style); } TEST_F(FormatTestCSharp, AccessModifiers) {