diff options
-rw-r--r-- | src/libs/cplusplus/pp-engine.cpp | 4 | ||||
-rw-r--r-- | tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp | 41 |
2 files changed, 43 insertions, 2 deletions
diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index 377e8c8e94..e14a7e93b8 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -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); } diff --git a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp index d3777d1998..a8dd56ea7b 100644 --- a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp +++ b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp @@ -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() |