Commit 3e9105e4 authored by Francois Ferrand's avatar Francois Ferrand Committed by Erik Verbruggen

Preprocessor: fix handling of first empty argument.

First empty argument used to be dropped: e.g. MACRO(,test) would be
expanded with one parameter only, with value 'test'.

Change-Id: I693fbb7faf1360f62266fa04c4b39c2de0d159a7
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@nokia.com>
parent ffd58c57
...@@ -369,7 +369,7 @@ const char *MacroExpander::expand(const char *__first, const char *__last, ...@@ -369,7 +369,7 @@ const char *MacroExpander::expand(const char *__first, const char *__last,
MacroExpander expand_actual (env, frame); MacroExpander expand_actual (env, frame);
const char *arg_end = skip_argument_variadics (actuals, macro, arg_it, __last); const char *arg_end = skip_argument_variadics (actuals, macro, arg_it, __last);
if (arg_it != arg_end) if (arg_it != arg_end || (arg_end != __last && *arg_end == ','))
{ {
actuals_ref.append(MacroArgumentReference(start_offset + (arg_it-start), arg_end - arg_it)); actuals_ref.append(MacroArgumentReference(start_offset + (arg_it-start), arg_end - arg_it));
const QByteArray actual (arg_it, arg_end - arg_it); const QByteArray actual (arg_it, arg_end - arg_it);
......
...@@ -43,6 +43,7 @@ Q_OBJECT ...@@ -43,6 +43,7 @@ Q_OBJECT
private Q_SLOTS: private Q_SLOTS:
void va_args(); void va_args();
void named_va_args(); void named_va_args();
void first_empty_macro_arg();
void unfinished_function_like_macro_call(); void unfinished_function_like_macro_call();
void nasty_macro_expansion(); void nasty_macro_expansion();
void tstst(); void tstst();
...@@ -82,6 +83,23 @@ void tst_Preprocessor::named_va_args() ...@@ -82,6 +83,23 @@ void tst_Preprocessor::named_va_args()
QVERIFY(preprocessed.contains("int f(int a,int b);")); QVERIFY(preprocessed.contains("int f(int a,int b);"));
} }
void tst_Preprocessor::first_empty_macro_arg()
{
Client *client = 0; // no client.
Environment env;
Preprocessor preprocess(client, &env);
QByteArray preprocessed = preprocess(QLatin1String("<stdin>"),
QByteArray("\n#define foo(a,b) a int b;"
"\nfoo(const,cVal)\n"
"\nfoo(,Val)\n"
"\nfoo( ,Val2)\n"));
QVERIFY(preprocessed.contains("const int cVal;"));
QVERIFY(preprocessed.contains("int Val;"));
QVERIFY(preprocessed.contains("int Val2;"));
}
void tst_Preprocessor::unfinished_function_like_macro_call() void tst_Preprocessor::unfinished_function_like_macro_call()
{ {
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