History

tccpp: Fix corner case of fnlike macro invocation

Arg substitution leaves placeholder marker in the stream for empty arguments. Those need to be skipped when searching for a fnlike macro invocation in the replacement list itself. See testcase.

Michael Matz committed 9 years ago

Commit 328b8261 parent 536ed763 files · +22 −2Browse files

Unified · Split

3 files
  1. tccpp.c +4 −2
  2. tests/pp/18.c +15 −0
  3. tests/pp/18.expect +3 −0
tccpp.c+4−2
@@ -3023,7 +3023,7 @@ static int next_argstream(Sym **nested_list, int can_read_stream, TokenString *w · 3022 unmodified lines
30233023 if (macro_ptr) {
30243024 p = macro_ptr, t = *p;
30253025 if (ws_str) {
3026− while (is_space(t) || TOK_LINEFEED == t)
3026+ while (is_space(t) || TOK_LINEFEED == t || TOK_PLCHLDR == t)
30273027 tok_str_add(ws_str, t), t = *++p;
30283028 }
30293029 if (t == 0 && can_read_stream) {
@@ -3152,7 +3152,9 @@ static int macro_subst_tok( · 122 unmodified lines
31523152 } else {
31533153 tok_str_free_str(ws_str.str);
31543154 }
3155− next_nomacro(); /* eat '(' */
3155+ do {
3156+ next_nomacro(); /* eat '(' */
3157+ } while (tok == TOK_PLCHLDR);
31563158
31573159 /* argument macro */
31583160 args = NULL;
tests/pp/18.c+15−0
@@ -0,0 +1,15 @@
1+#define M_RETI_ARG27(x,y,z,aa, ...) aa
2+#define M_RET_ARG27(...) M_RETI_ARG27(__VA_ARGS__)
3+#define M_COMMA_P(...) M_RET_ARG27(__VA_ARGS__, 1, 1, 0, useless)
4+#define M_EMPTYI_DETECT(...) 0, 1,
5+#define M_EMPTYI_P_C1(...) M_COMMA_P(M_EMPTYI_DETECT __VA_ARGS__ () )
6+#define EX
7+#define empty(x)
8+#define fnlike(x) yeah x
9+/* If the following macro is called with empty arg (X183), the use
10+ of 'x' between fnlike and '(' doesn't hinder the recognition of this
11+ being a further fnlike macro invocation. */
12+#define usefnlike(x) fnlike x (x)
13+X181 M_EMPTYI_P_C1()
14+X182 M_EMPTYI_P_C1(x)
15+X183 usefnlike()
tests/pp/18.expect+3−0
@@ -0,0 +1,3 @@
1+X181 1
2+X182 0
3+X183 yeah

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t