forked from qt-creator/qt-creator
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>
This commit is contained in:
committed by
Orgad Shaneh
parent
dabdb60299
commit
67caa75c56
@@ -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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user