Commit 4d18710f authored by Francois Ferrand's avatar Francois Ferrand Committed by Nikolai Kosjar

C++: fix handling of empty va_args macro arguments.

Preprocessor did not correctly handle when variadic macro arguments were not
provided at all, if there were other arguments: macro was not expanded
in case only the non variadic arguments were given.

 #define MACRO(...)       used to work fine for 0 or more arguments.
 #define MACRO(ARG0, ...) used to work only for 2 or more arguments, now fixed.

Change-Id: I64e9199ceccae05618a49931c2adad8e4f9471ba
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent feeff29f
...@@ -945,6 +945,8 @@ bool Preprocessor::handleIdentifier(PPToken *tk) ...@@ -945,6 +945,8 @@ bool Preprocessor::handleIdentifier(PPToken *tk)
bool hasMatchingArgs = false; bool hasMatchingArgs = false;
if (hasArgs) { if (hasArgs) {
const int expectedArgCount = macro->formals().size(); const int expectedArgCount = macro->formals().size();
if (macro->isVariadic() && allArgTks.size() == expectedArgCount - 1)
allArgTks.push_back(QVector<PPToken>());
const int actualArgCount = allArgTks.size(); const int actualArgCount = allArgTks.size();
if (expectedArgCount == actualArgCount if (expectedArgCount == actualArgCount
|| (macro->isVariadic() && actualArgCount > expectedArgCount - 1) || (macro->isVariadic() && actualArgCount > expectedArgCount - 1)
......
...@@ -317,6 +317,7 @@ private: ...@@ -317,6 +317,7 @@ private:
private slots: private slots:
void va_args(); void va_args();
void named_va_args(); void named_va_args();
void extra_va_args();
void defined(); void defined();
void defined_data(); void defined_data();
void empty_macro_args(); void empty_macro_args();
...@@ -413,6 +414,23 @@ void tst_Preprocessor::named_va_args() ...@@ -413,6 +414,23 @@ void tst_Preprocessor::named_va_args()
QCOMPARE(simplified(preprocessed), QString("int f();int f(int a);int f(int a,int b);")); QCOMPARE(simplified(preprocessed), QString("int f();int f(int a);int f(int a,int b);"));
} }
void tst_Preprocessor::extra_va_args()
{
Client *client = 0; // no client.
Environment env;
Preprocessor preprocess(client, &env);
QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"),
"#define foo(ret, ...) ret f(__VA_ARGS__);\n"
"\nfoo(int)\n"
"\nfoo(float,int b)\n"
"\nfoo(long,int b,int c)\n",
true, false);
preprocessed = preprocessed.simplified();
QCOMPARE(simplified(preprocessed), QString("int f();float f(int b);long f(int b,int c);"));
}
void tst_Preprocessor::empty_macro_args() void tst_Preprocessor::empty_macro_args()
{ {
Client *client = 0; // no client. Client *client = 0; // no client.
......
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