diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index 9c86b7e35d2f748513efb1bfd6f4c7e594d9bb7d..21440bc86c13121c1579814992bf3da779938977 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -2039,6 +2039,15 @@ bool Preprocessor::atStartOfOutputLine() const void Preprocessor::maybeStartOutputLine() { QByteArray &buffer = currentOutputBuffer(); - if (!buffer.isEmpty() && !buffer.endsWith('\n')) + if (buffer.isEmpty()) + return; + if (!buffer.endsWith('\n')) + buffer.append('\n'); + // If previous line ends with \ (possibly followed by whitespace), add another \n + const char *start = buffer.constData(); + const char *ch = start + buffer.length() - 2; + while (ch > start && (*ch != '\n') && std::isspace(*ch)) + --ch; + if (*ch == '\\') buffer.append('\n'); } diff --git a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp index b262db3b40fcf6ac5c182010c5beb597f2f42429..ca3460335d24070b9fa1b8711108cc27c79cfc13 100644 --- a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp +++ b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp @@ -1453,6 +1453,31 @@ void tst_Preprocessor::comments_within_data() "\n" "int foo = 4;" ); + + QTest::newRow("joined_unterminated") << _( + "// comment \\\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "int foo = 4;" + ) << _( + "# 1 \"\"\n" + "# 12 \"\"\n" + "int foo = 4;" + ) << _( + "# 1 \"\"\n" + "// comment \\\n" + "\n" + "# 12 \"\"\n" + "int foo = 4;" + ); } void tst_Preprocessor::comments_before_args()