diff options
author | Leandro Melo <leandro.melo@nokia.com> | 2012-06-12 15:59:07 +0200 |
---|---|---|
committer | hjk <qthjk@ovi.com> | 2012-06-19 12:47:44 +0200 |
commit | f978400ae5c9a7802c110ccd77db9a4dc8a95262 (patch) | |
tree | d83343a0704904581bffe21ae1aa16a862b900e8 /tests | |
parent | 7eaaab6e73c005d74ad3d4de53ca04bf1cb517c0 (diff) | |
download | qt-creator-f978400ae5c9a7802c110ccd77db9a4dc8a95262.tar.gz |
C++: Better handling of arg count mismatch in macros
Do not expand function-like macros at all when there's a mismatch
in the parameter/argument count.
The report below raises the issue but its expected result is not
correct. This would be the more appropriate fix.
Task-number: QTCREATORBUG-7225
Change-Id: Ide8580faa7b724d3e8b396ec1f899cc5ca7f9e7e
Reviewed-by: hjk <qthjk@ovi.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp | 58 |
1 files changed, 13 insertions, 45 deletions
diff --git a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp index e703cf2f34..b5cb82649d 100644 --- a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp +++ b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp @@ -300,10 +300,6 @@ protected: } static QString simplified(QByteArray buf); -private /* not corrected yet */: - void param_expanding_as_multiple_params(); - void macro_argument_expansion(); - private slots: void defined(); void defined_data(); @@ -447,49 +443,21 @@ void tst_Preprocessor::macro_args_count() void tst_Preprocessor::invalid_param_count() { - Client *client = 0; // no client. - Environment env; - - Preprocessor preprocess(client, &env); - // The following is illegal, but shouldn't crash the preprocessor. - // GCC says: 3:14: error: macro "foo" requires 2 arguments, but only 1 given - QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"), - "\n#define foo(a,b) int f(a,b);" - "\n#define ARGS(t) t a,t b" - "\nfoo(ARGS(int))", - true, false); - // do not verify the output: it's illegal, so anything might be outputted. -} - -void tst_Preprocessor::param_expanding_as_multiple_params() -{ - Client *client = 0; // no client. Environment env; + QByteArray output; + MockClient client(&env, &output); + Preprocessor preprocess(&client, &env); + // The following are illegal, but shouldn't crash the preprocessor. + preprocess.run(QLatin1String("<stdin>"), + "\n#define foo(a,b) int f(a,b);" + "\n#define ARGS(t) t a,t b" + "\nfoo(ARGS(int))" + "\nfoo()" + "\nfoo(int a, int b, int c)", + true, false); - Preprocessor preprocess(client, &env); - QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"), - "\n#define foo(a,b) int f(a,b);" - "\n#define ARGS(t) t a,t b" - "\nfoo(ARGS(int))", - false, true); - QCOMPARE(simplified(preprocessed), QString("int f(int a,int b);")); -} - -void tst_Preprocessor::macro_argument_expansion() //QTCREATORBUG-7225 -{ - Client *client = 0; // no client. - Environment env; - - Preprocessor preprocess(client, &env); - QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"), - "\n#define BAR1 2,3,4" - "\n#define FOO1(a,b,c) a+b+c" - "\nvoid test2(){" - "\nint x=FOO1(BAR1);" - "\n}", - false, true); - QCOMPARE(simplified(preprocessed), QString("void test2(){int x=2+3+4;}")); - + // Output is not that relevant but check that nothing triggered expansion. + QCOMPARE(client.macroArgsCount(), QList<int>()); } void tst_Preprocessor::macro_uses() |