C++: Expand arguments in nested function-like macros

Task-number: QTCREATORBUG-13219
Change-Id: I319fe39d696ccc28230d421b1395faf4dd452b03
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2015-01-02 11:33:32 +02:00
committed by Orgad Shaneh
parent 5460250281
commit c24ffc4dee
2 changed files with 12 additions and 6 deletions

View File

@@ -905,7 +905,7 @@ void Preprocessor::skipPreprocesorDirective(PPToken *tk)
bool Preprocessor::handleIdentifier(PPToken *tk) bool Preprocessor::handleIdentifier(PPToken *tk)
{ {
ScopedBoolSwap s(m_state.m_inPreprocessorDirective, true); ScopedBoolSwap s(m_state.m_inPreprocessorDirective, !tk->f.expanded);
static const QByteArray ppLine("__LINE__"); static const QByteArray ppLine("__LINE__");
static const QByteArray ppFile("__FILE__"); static const QByteArray ppFile("__FILE__");

View File

@@ -1877,21 +1877,27 @@ void tst_Preprocessor::concat()
"#define concat(x,y) x ## y\n" "#define concat(x,y) x ## y\n"
"#define xconcat(x, y) concat(x, y)\n" "#define xconcat(x, y) concat(x, y)\n"
"#define FOO 42\n" "#define FOO 42\n"
"int var = xconcat(0x, FOO);\n"; "int var1 = concat(0x, FOO);\n"
"int var2 = xconcat(0x, FOO);\n";
QByteArray prep = preprocess.run(QLatin1String("<stdin>"), input); QByteArray prep = preprocess.run(QLatin1String("<stdin>"), input);
const QByteArray output = _( const QByteArray output = _(
"# 1 \"<stdin>\"\n" "# 1 \"<stdin>\"\n"
"\n" "\n"
"\n" "\n"
"\n" "\n"
"int var =\n" "int var1 =\n"
"# expansion begin 87,7 ~1\n" "# expansion begin 88,6 ~1\n"
"0x42\n" "0xFOO\n"
"# expansion end\n" "# expansion end\n"
"# 4 \"<stdin>\"\n" "# 4 \"<stdin>\"\n"
" ;\n" " ;\n"
"int var2 =\n"
"# expansion begin 116,7 ~1\n"
"0x42\n"
"# expansion end\n"
"# 5 \"<stdin>\"\n"
" ;\n"
); );
QEXPECT_FAIL(0, "QTCREATORBUG-13219", Abort);
QCOMPARE(prep.constData(), output.constData()); QCOMPARE(prep.constData(), output.constData());
} }