From fb6331e0fa34338f4ff8a54d5efabc8a6b46f119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Sun, 18 Jan 2015 22:00:10 +0100 Subject: [PATCH] Fix macro expansion of empty args. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Reimar Döffinger --- tccpp.c | 2 +- tests/tests2/71_macro_empty_arg.c | 9 +++++++++ tests/tests2/71_macro_empty_arg.expect | 1 + tests/tests2/Makefile | 4 +++- 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 tests/tests2/71_macro_empty_arg.c create mode 100644 tests/tests2/71_macro_empty_arg.expect diff --git a/tccpp.c b/tccpp.c index 4c7cf80a..bc2d4a26 100644 --- a/tccpp.c +++ b/tccpp.c @@ -2640,7 +2640,7 @@ static int *macro_arg_subst(Sym **nested_list, const int *macro_str, Sym *args) tok_str_add2(&str, t1, &cval); } } - } else { + } else if (*st != TOK_PLCHLDR) { /* NOTE: the stream cannot be read when macro substituing an argument */ macro_subst(&str, nested_list, st, NULL); diff --git a/tests/tests2/71_macro_empty_arg.c b/tests/tests2/71_macro_empty_arg.c new file mode 100644 index 00000000..f0d3511b --- /dev/null +++ b/tests/tests2/71_macro_empty_arg.c @@ -0,0 +1,9 @@ +#include + +#define T(a,b,c) a b c + +int main(void) +{ + printf("%d", T(1,+,2) T(+,,) T(,2,*) T(,7,) T(,,)); + return 0; +} diff --git a/tests/tests2/71_macro_empty_arg.expect b/tests/tests2/71_macro_empty_arg.expect new file mode 100644 index 00000000..98d9bcb7 --- /dev/null +++ b/tests/tests2/71_macro_empty_arg.expect @@ -0,0 +1 @@ +17 diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile index 8e11f2ca..ec636abf 100644 --- a/tests/tests2/Makefile +++ b/tests/tests2/Makefile @@ -89,7 +89,9 @@ TESTS = \ 67_macro_concat.test \ 68_macro_param_list_err_1.test \ 69_macro_param_list_err_2.test \ - 70_floating_point_literals.test + 70_floating_point_literals.test \ + 71_macro_empty_arg.test \ + # 34_array_assignment.test -- array assignment is not in C standard