// FIXME: We need to check whether we're in a preprocessor directive, even
// if all tokens fit - the next line might be a preprocessor directive,
// too, in which case we need to account for the possible escaped newline.
- if (Columns > Style.ColumnLimit ||
+ if (Columns > Style.ColumnLimit - (Line.InPPDirective ? 1 : 0) ||
(Annotations[i].MustBreakBefore &&
Annotations[i].Type != TokenAnnotation::TT_CtorInitializerColon)) {
FitsOnALine = false;
}
TEST_F(FormatTest, IndentsPPDirectiveInReducedSpace) {
- // If the macro fits in one line, we have the full width.
- verifyFormat("#define A(B)", getLLVMStyleWithColumns(12));
+ // If the macro fits in one line, we still do not get the full
+ // line, as only the next line decides whether we need an escaped newline and
+ // thus use the last column.
+ verifyFormat("#define A(B)", getLLVMStyleWithColumns(13));
- verifyFormat("#define A(\\\n B)", getLLVMStyleWithColumns(11));
- verifyFormat("#define AA(\\\n B)", getLLVMStyleWithColumns(11));
+ verifyFormat("#define A( \\\n B)", getLLVMStyleWithColumns(12));
+ verifyFormat("#define AA(\\\n B)", getLLVMStyleWithColumns(12));
verifyFormat("#define A( \\\n A, B)", getLLVMStyleWithColumns(12));
}
getLLVMStyleWithColumns(11)));
}
+TEST_F(FormatTest, CalculateSpaceOnConsecutiveLinesInMacro) {
+ verifyFormat("#define A \\\n"
+ " int v( \\\n"
+ " a); \\\n"
+ " int i;", getLLVMStyleWithColumns(11));
+}
+
TEST_F(FormatTest, MixingPreprocessorDirectivesAndNormalCode) {
EXPECT_EQ(
"#define ALooooooooooooooooooooooooooooooooooooooongMacro("