From 4c43655cec5c117f8438f795846290e569b3727e Mon Sep 17 00:00:00 2001 From: Francois Ferrand Date: Thu, 17 Jan 2013 17:26:26 +0100 Subject: [PATCH] C++: fix macro calls with comment before arguments When in 'keep comments' mode, the preprocessor does not properly handle macro calls with comments between the macro name and the opening parenthesis: "FOO /*something to say*/ (45)". Change-Id: I6fe733242e4d2ccff2985d17399d0a084917415a Reviewed-by: Erik Verbruggen --- src/libs/cplusplus/pp-engine.cpp | 7 ++++++ .../preprocessor/tst_preprocessor.cpp | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index 9938735fba9..705ea1b1a38 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -1330,6 +1330,13 @@ bool Preprocessor::collectActualArguments(PPToken *tk, QVector lex(tk); // consume the identifier + // consume comments + while (tk->isComment()) { + lex(tk); + if (!tk) + return false; + } + if (tk->isNot(T_LPAREN)) //### TODO: error message return false; diff --git a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp index 945d0825f5a..4cc38afe76b 100644 --- a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp +++ b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp @@ -329,6 +329,7 @@ private slots: void dont_eagerly_expand_data(); void comparisons_data(); void comparisons(); + void comments_before_args(); void comments_within(); void comments_within_data(); void comments_within2(); @@ -1239,6 +1240,28 @@ void tst_Preprocessor::comments_within_data() QTest::newRow("case 7") << original << expected; } +void tst_Preprocessor::comments_before_args() +{ + Client *client = 0; // no client. + Environment env; + + Preprocessor preprocess(client, &env); + preprocess.setKeepComments(true); + QByteArray preprocessed = preprocess.run(QLatin1String(""), + "\n#define foo(a,b) int a = b;" + "\nfoo/*C comment*/(a,1)\n" + "\nfoo/**Doxygen comment*/(b,2)\n" + "\nfoo//C++ comment\n(c,3)\n" + "\nfoo///Doxygen C++ comment\n(d,4)\n" + "\nfoo/*multiple*///comments\n/**as well*/(e,5)\n", + true, false); + + preprocessed = preprocessed.simplified(); +// DUMP_OUTPUT(preprocessed); + QCOMPARE(simplified(preprocessed), + QString("int a=1;int b=2;int c=3;int d=4;int e=5;")); +} + void tst_Preprocessor::comments_within2() { compare_input_output(true);