if (Current.FormatTok.MustBreakBefore) {
Current.MustBreakBefore = true;
} else {
- if (Current.Type == TT_CtorInitializerColon || Current.Parent->Type ==
- TT_LineComment || (Current.is(tok::string_literal) &&
- Current.Parent->is(tok::string_literal))) {
+ if (Current.Type == TT_LineComment) {
+ Current.MustBreakBefore = Current.FormatTok.NewlinesBefore > 0;
+ } else if (Current.Type == TT_CtorInitializerColon ||
+ Current.Parent->Type == TT_LineComment ||
+ (Current.is(tok::string_literal) &&
+ Current.Parent->is(tok::string_literal))) {
Current.MustBreakBefore = true;
} else {
Current.MustBreakBefore = false;
return false;
if (Right.is(tok::comment))
- return !Right.Children.empty();
+ // We rely on MustBreakBefore being set correctly here as we should not
+ // change the "binding" behavior of a comment.
+ return false;
+
if (Right.is(tok::r_paren) || Right.is(tok::l_brace) ||
Right.is(tok::greater))
return false;
verifyFormat("void f() {\n"
" // Doesn't do anything\n"
"}");
+ verifyFormat("void f(int i, // some comment (probably for i)\n"
+ " int j, // some comment (probably for j)\n"
+ " int k); // some comment (probably for k)");
+ verifyFormat("void f(int i,\n"
+ " // some comment (probably for j)\n"
+ " int j,\n"
+ " // some comment (probably for k)\n"
+ " int k);");
verifyFormat("int i // This is a fancy variable\n"
" = 5;");