diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2014-02-05 08:37:33 +0200 |
---|---|---|
committer | Orgad Shaneh <orgads@gmail.com> | 2014-02-24 21:56:52 +0100 |
commit | 67caa75c56d303c9a4b72342959337144a97b1a7 (patch) | |
tree | ec5866eeb65b36eaba5ec481dab99e3a8b3721e7 | |
parent | dabdb60299d01d12857f45baa2b04f10077c27cc (diff) | |
download | qt-creator-67caa75c56d303c9a4b72342959337144a97b1a7.tar.gz |
C++: Fix preprocessing of uncontinued line-escaping
The following snippet demonstrates the problem:
--- snip ---
// comment \
#include <something.h>
...
class Foo
{
...
};
--- snap ---
If there are >=9 empty/preprocessor lines, the preprocessed source
becomes
// comment \
# 12 "file.cpp"
...
The lexer considers the line marker as a continued C++ comment, and
highlighting is broken
Change-Id: I30a2fc7d19b279316e9273697179c90d81099573
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
-rw-r--r-- | src/libs/cplusplus/pp-engine.cpp | 11 | ||||
-rw-r--r-- | tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp | 25 |
2 files changed, 35 insertions, 1 deletions
diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index 9c86b7e35d..21440bc86c 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 b262db3b40..ca3460335d 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 \"<stdin>\"\n" + "# 12 \"<stdin>\"\n" + "int foo = 4;" + ) << _( + "# 1 \"<stdin>\"\n" + "// comment \\\n" + "\n" + "# 12 \"<stdin>\"\n" + "int foo = 4;" + ); } void tst_Preprocessor::comments_before_args() |