Commit 67caa75c authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

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: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent dabdb602
......@@ -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');
}
......@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment