C++: fix trigraph parsing in macros.

Trigraphs must only be parsed before/during preprocessing. The preprocessor
will now replace trigraphs with their standard form, and re-lexing in
TranslationUnit will not try to parse any trigraph.

Also added a few missing trigraphs: ??=, ??', ??! and ??-.

Task-number: QTCREATORBUG-13253
Change-Id: I1723ed53b00090b878c22b83b7e963b647b65f72
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Francois Ferrand
2014-10-24 14:55:43 +02:00
parent 9057143228
commit 41b232962a
6 changed files with 131 additions and 9 deletions

View File

@@ -405,6 +405,7 @@ private slots:
void concat();
void excessive_nesting();
void multi_byte_code_point_in_expansion();
void trigraph();
};
// Remove all #... lines, and 'simplify' string, to allow easily comparing the result
@@ -2092,6 +2093,29 @@ void tst_Preprocessor::compare_input_output(bool keepComments)
QVERIFY(compare(prep, output));
}
void tst_Preprocessor::trigraph()
{
Environment env;
Preprocessor preprocess(0, &env);
// We cannot use actual trigraphs in strings, they would be replaced by the preprocessor when
// compiling the test, so we use strings with 'j' character instead of '?', and perform a
// replacement at runtime.
// Trigraphs in source code are replaced
QByteArray prep = preprocess.run(QLatin1String("<stdin>"),
QByteArray("jj( jj) jj< jj> jj= jj=jj= jj' jj'= jj! jj!= jj- jj-=").replace('j', '?'),
true, false);
QCOMPARE(prep.constData(), "[ ] { } # ## ^ ^= | |= ~ ~=");
// Trigraphs that appear after macro expansion are not replaced
prep = preprocess.run(QLatin1String("<stdin>"),
"#define TRIGRAPH(x...) ? ## x ## ? ## x ## =\n"
"TRIGRAPH()",
true, false);
QCOMPARE(prep.constData(), QByteArray("\njj=").replace('j', '?').data());
}
QTEST_APPLESS_MAIN(tst_Preprocessor)
#include "tst_preprocessor.moc"