aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Format/TokenAnnotator.cpp5
-rw-r--r--unittests/Format/FormatTest.cpp6
2 files changed, 9 insertions, 2 deletions
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index 24e2b1f87e..44421c4bbe 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -939,6 +939,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
return 150;
if (Left.is(tok::coloncolon))
return 500;
+ if (Left.isOneOf(tok::kw_class, tok::kw_struct))
+ return 5000;
if (Left.Type == TT_RangeBasedForLoopColon ||
Left.Type == TT_InheritanceColon)
@@ -1176,7 +1178,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
if (Left.is(tok::identifier) && Right.is(tok::string_literal))
return true;
return (isBinaryOperator(Left) && Left.isNot(tok::lessless)) ||
- Left.isOneOf(tok::comma, tok::coloncolon, tok::semi, tok::l_brace) ||
+ Left.isOneOf(tok::comma, tok::coloncolon, tok::semi, tok::l_brace,
+ tok::kw_class, tok::kw_struct) ||
Right.isOneOf(tok::lessless, tok::arrow, tok::period, tok::colon) ||
(Left.is(tok::r_paren) && Left.Type != TT_CastRParen &&
Right.isOneOf(tok::identifier, tok::kw___attribute)) ||
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 54e7381207..0ef241e34e 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -987,7 +987,7 @@ TEST_F(FormatTest, SeparatesLogicalBlocks) {
"};"));
}
-TEST_F(FormatTest, FormatsDerivedClass) {
+TEST_F(FormatTest, FormatsClasses) {
verifyFormat("class A : public B {\n};");
verifyFormat("class A : public ::B {\n};");
@@ -1009,6 +1009,10 @@ TEST_F(FormatTest, FormatsDerivedClass) {
" public F,\n"
" public G {\n"
"};");
+
+ verifyFormat("class\n"
+ " ReallyReallyLongClassName {\n};",
+ getLLVMStyleWithColumns(32));
}
TEST_F(FormatTest, FormatsVariableDeclarationsAfterStructOrClass) {