diff options
| author | Manuel Klimek <klimek@google.com> | 2013-01-07 09:24:17 +0000 |
|---|---|---|
| committer | Manuel Klimek <klimek@google.com> | 2013-01-07 09:24:17 +0000 |
| commit | 38ba11e492695b1b80821142af5f909e08aeb599 (patch) | |
| tree | 8a009f0c488a95e3cdf7e41976ff313afef36546 | |
| parent | 342cc255d0e107d84132744a8a021674fb46314a (diff) | |
| download | bcm5719-llvm-38ba11e492695b1b80821142af5f909e08aeb599.tar.gz bcm5719-llvm-38ba11e492695b1b80821142af5f909e08aeb599.zip | |
Do not ever allow using the full line in preprocessor directives.
We would format:
#define A \
int f(a); int i;
as
#define A \
int f(a);\
int i
The fix will break up macro definitions that could fit a line, but hit
the last column; fixing that is more involved, though, as it requires
looking at the following line.
llvm-svn: 171715
| -rw-r--r-- | clang/lib/Format/Format.cpp | 2 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 17 |
2 files changed, 14 insertions, 5 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 35c1e403c6d..7b3c575d0b1 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -137,7 +137,7 @@ public: // 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; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 27ca53c1eab..54999e1f634 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -413,11 +413,13 @@ TEST_F(FormatTest, EndOfFileEndsPPDirective) { } 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)); } @@ -490,6 +492,13 @@ TEST_F(FormatTest, EscapedNewlineAtStartOfTokenInMacroDefinition) { 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(" |

