forked from qt-creator/qt-creator
C++: Discard comments in macro definitions
Task-number: QTCREATORBUG-7815 Change-Id: Id3e6b018bfd58b0f0072c637d69721a4bde1603a Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
@@ -1542,6 +1542,8 @@ void Preprocessor::handleDefineDirective(PPToken *tk)
|
|||||||
previousOffset = tk->offset;
|
previousOffset = tk->offset;
|
||||||
previousLine = tk->lineno;
|
previousLine = tk->lineno;
|
||||||
|
|
||||||
|
// Discard comments in macro definitions (keep comments flag doesn't apply here).
|
||||||
|
if (!tk->isComment())
|
||||||
bodyTokens.push_back(*tk);
|
bodyTokens.push_back(*tk);
|
||||||
|
|
||||||
lex(tk);
|
lex(tk);
|
||||||
|
|||||||
@@ -1076,7 +1076,6 @@ void tst_Preprocessor::comments_within()
|
|||||||
{
|
{
|
||||||
compare_input_output();
|
compare_input_output();
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_Preprocessor::comments_within_data()
|
void tst_Preprocessor::comments_within_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QByteArray>("input");
|
QTest::addColumn<QByteArray>("input");
|
||||||
@@ -1219,6 +1218,26 @@ void tst_Preprocessor::comments_within_data()
|
|||||||
"# expansion end\n"
|
"# expansion end\n"
|
||||||
"# 8 \"<stdin>\"\n";
|
"# 8 \"<stdin>\"\n";
|
||||||
QTest::newRow("case 6") << original << expected;
|
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()
|
void tst_Preprocessor::comments_within2()
|
||||||
@@ -1373,6 +1392,26 @@ void tst_Preprocessor::comments_within2_data()
|
|||||||
"# expansion end\n"
|
"# expansion end\n"
|
||||||
"# 8 \"<stdin>\"\n";
|
"# 8 \"<stdin>\"\n";
|
||||||
QTest::newRow("case 6") << original << expected;
|
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()
|
void tst_Preprocessor::multiline_strings()
|
||||||
|
|||||||
Reference in New Issue
Block a user