diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index fec85f1174da4..0e1b5e95e9ddd 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -593,9 +593,10 @@ class LineJoiner { 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 index dba76b5216146..918f8aed83e9b 100644 --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -70,6 +70,30 @@ TEST_F(FormatTestCSharp, CSharpClass) { " 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) {