Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4050,7 +4050,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
ChildSize + Current->SpacesRequiredBefore;
}

if (Current->is(TT_CtorInitializerColon))
if (Current->isOneOf(TT_CtorInitializerColon, TT_LambdaLSquare))
InFunctionDecl = false;

// FIXME: Only calculate this if CanBreakBefore is true once static
Expand Down Expand Up @@ -4211,7 +4211,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
}
if (Right.is(TT_PointerOrReference))
return 190;
if (Right.is(TT_TrailingReturnArrow))
if (!InFunctionDecl && Right.is(TT_TrailingReturnArrow))
return 110;
if (Left.is(tok::equal) && Right.is(tok::l_brace))
return 160;
Expand Down
16 changes: 16 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class TokenAnnotatorTest : public testing::Test {
EXPECT_EQ((FormatTok)->getPrecedence(), Prec) << *(FormatTok)
#define EXPECT_BRACE_KIND(FormatTok, Kind) \
EXPECT_EQ(FormatTok->getBlockKind(), Kind) << *(FormatTok)
#define EXPECT_SPLIT_PENALTY(FormatTok, Penalty) \
EXPECT_EQ(FormatTok->SplitPenalty, (unsigned)(Penalty)) << *(FormatTok)
#define EXPECT_TOKEN(FormatTok, Kind, Type) \
do { \
EXPECT_TOKEN_KIND(FormatTok, Kind); \
Expand Down Expand Up @@ -3369,6 +3371,20 @@ TEST_F(TokenAnnotatorTest, GNULanguageStandard) {
EXPECT_TOKEN(Tokens[2], tok::spaceship, TT_BinaryOperator);
}

TEST_F(TokenAnnotatorTest, SplitPenalty) {
auto Style = getLLVMStyle();
Style.ColumnLimit = 20;

auto Tokens = annotate("class foo {\n"
" auto bar()\n"
" -> bool;\n"
"};",
Style);
ASSERT_EQ(Tokens.size(), 13u);
EXPECT_TOKEN(Tokens[7], tok::arrow, TT_TrailingReturnArrow);
EXPECT_SPLIT_PENALTY(Tokens[7], 23);
}

} // namespace
} // namespace format
} // namespace clang