if (I[1]->InPPDirective != (*I)->InPPDirective ||
(I[1]->InPPDirective && I[1]->First->HasUnescapedNewline))
return 0;
+ Limit = LimitConsideringMacros(I + 1, E, Limit);
AnnotatedLine &Line = **I;
if (Line.Last->isNot(tok::r_paren))
return 0;
// Check that we still have three lines and they fit into the limit.
if (I + 2 == E || I[2]->Type == LT_Invalid)
return 0;
+ Limit = LimitConsideringMacros(I + 2, E, Limit);
if (!nextTwoLinesFitInto(I, Limit))
return 0;
return 0;
}
+ /// Returns the modified column limit for \p I if it is inside a macro and
+ /// needs a trailing '\'.
+ unsigned
+ LimitConsideringMacros(SmallVectorImpl<AnnotatedLine *>::const_iterator I,
+ SmallVectorImpl<AnnotatedLine *>::const_iterator E,
+ unsigned Limit) {
+ if (I[0]->InPPDirective && I + 1 != E &&
+ !I[1]->First->HasUnescapedNewline && !I[1]->First->is(tok::eof)) {
+ return Limit < 2 ? 0 : Limit - 2;
+ }
+ return Limit;
+ }
+
bool nextTwoLinesFitInto(SmallVectorImpl<AnnotatedLine *>::const_iterator I,
unsigned Limit) {
return 1 + I[1]->Last->TotalLength + 1 + I[2]->Last->TotalLength <= Limit;
" : b(0) {\n"
"}",
format("A()\n:b(0)\n{\n}", DoNotMergeNoColumnLimit));
+
+ verifyFormat("#define A \\\n"
+ " void f() { \\\n"
+ " int i; \\\n"
+ " }",
+ getLLVMStyleWithColumns(20));
+ verifyFormat("#define A \\\n"
+ " void f() { int i; }",
+ getLLVMStyleWithColumns(21));
+ verifyFormat("#define A \\\n"
+ " void f() { \\\n"
+ " int i; \\\n"
+ " } \\\n"
+ " int j;",
+ getLLVMStyleWithColumns(22));
+ verifyFormat("#define A \\\n"
+ " void f() { int i; } \\\n"
+ " int j;",
+ getLLVMStyleWithColumns(23));
}
TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) {
" if (true) continue;\n"
"}",
ShortMergedIf);
+ ShortMergedIf.ColumnLimit = 29;
+ verifyFormat("#define A \\\n"
+ " if (aaaaaaaaaa) return 1; \\\n"
+ " return 2;",
+ ShortMergedIf);
+ ShortMergedIf.ColumnLimit = 28;
+ verifyFormat("#define A \\\n"
+ " if (aaaaaaaaaa) \\\n"
+ " return 1; \\\n"
+ " return 2;",
+ ShortMergedIf);
}
TEST_F(FormatTest, BlockCommentsInControlLoops) {