Commit d1b65bbf authored by Leandro Melo's avatar Leandro Melo

C++: Discard comments in macro definitions

Task-number: QTCREATORBUG-7815

Change-Id: Id3e6b018bfd58b0f0072c637d69721a4bde1603a
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent c3f50e31
......@@ -1542,7 +1542,9 @@ void Preprocessor::handleDefineDirective(PPToken *tk)
previousOffset = tk->offset;
previousLine = tk->lineno;
bodyTokens.push_back(*tk);
// Discard comments in macro definitions (keep comments flag doesn't apply here).
if (!tk->isComment())
bodyTokens.push_back(*tk);
lex(tk);
}
......
......@@ -1076,7 +1076,6 @@ void tst_Preprocessor::comments_within()
{
compare_input_output();
}
void tst_Preprocessor::comments_within_data()
{
QTest::addColumn<QByteArray>("input");
......@@ -1219,6 +1218,26 @@ void tst_Preprocessor::comments_within_data()
"# expansion end\n"
"# 8 \"<stdin>\"\n";
QTest::newRow("case 6") << original << expected;
original =
"#define FOO 0 //coment\n"
"#define BAR (1 == FOO)\n"
"void foo() {\n"
" if (BAR) {}\n"
"}\n";
expected =
"# 1 \"<stdin>\"\n"
"\n"
"\n"
"void foo() {\n"
" if (\n"
"# expansion begin 67,3 ~5\n"
"(1 == 0)\n"
"# expansion end\n"
"# 4 \"<stdin>\"\n"
" ) {}\n"
"}\n";
QTest::newRow("case 7") << original << expected;
}
void tst_Preprocessor::comments_within2()
......@@ -1373,6 +1392,26 @@ void tst_Preprocessor::comments_within2_data()
"# expansion end\n"
"# 8 \"<stdin>\"\n";
QTest::newRow("case 6") << original << expected;
original =
"#define FOO 0 //coment\n"
"#define BAR (1 == FOO)\n"
"void foo() {\n"
" if (BAR) {}\n"
"}\n";
expected =
"# 1 \"<stdin>\"\n"
"\n"
"\n"
"void foo() {\n"
" if (\n"
"# expansion begin 67,3 ~5\n"
"(1 == 0)\n"
"# expansion end\n"
"# 4 \"<stdin>\"\n"
" ) {}\n"
"}\n";
QTest::newRow("case 7") << original << expected;
}
void tst_Preprocessor::multiline_strings()
......
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