History

Prevent ## to appear at start or end of macro

Thomas Preud'homme committed 12 years ago

Commit a715d711 parent 91d4db66 files · +20 −4Browse files

Unified · Split

6 files
  1. tccpp.c +11 −3
  2. tests/tests2/65_macro_concat_start.c +2 −0
  3. tests/tests2/65_macro_concat_start.expect +1 −0
  4. tests/tests2/66_macro_concat_end.c +2 −0
  5. tests/tests2/66_macro_concat_end.expect +1 −0
  6. tests/tests2/Makefile +3 −1
tccpp.c+11−3
@@ -1213,9 +1213,9 @@ static void tok_print(int *str) · 1212 unmodified lines
1213ST_FUNC void parse_define(void)1213ST_FUNC void parse_define(void)
1214{1214{
1215 Sym *s, *first, **ps;1215 Sym *s, *first, **ps;
1216 int v, t, varg, is_vaargs, spc;1216 int v, t, varg, is_vaargs, spc, ptok, macro_list_start;
1217 TokenString str;1217 TokenString str;
1218 1218
1219 v = tok;1219 v = tok;
1220 if (v < TOK_IDENT)1220 if (v < TOK_IDENT)
1221 tcc_error("invalid macro name '%s'", get_tok_str(tok, &tokc));1221 tcc_error("invalid macro name '%s'", get_tok_str(tok, &tokc));
@@ -1254,8 +1254,13 @@ ST_FUNC void parse_define(void) · 32 unmodified lines
1254 tok_str_new(&str);1254 tok_str_new(&str);
1255 spc = 2;1255 spc = 2;
1256 /* EOF testing necessary for '-D' handling */1256 /* EOF testing necessary for '-D' handling */
1257 ptok = 0;
1258 macro_list_start = 1;
1257 while (tok != TOK_LINEFEED && tok != TOK_EOF) {1259 while (tok != TOK_LINEFEED && tok != TOK_EOF) {
1258 /* remove spaces around ## and after '#' */ 1260 if (!macro_list_start && spc == 2 && tok == TOK_TWOSHARPS)
1261 tcc_error("'##' invalid at start of macro");
1262 ptok = tok;
1263 /* remove spaces around ## and after '#' */
1259 if (TOK_TWOSHARPS == tok) {1264 if (TOK_TWOSHARPS == tok) {
1260 if (1 == spc)1265 if (1 == spc)
1261 --str.len;1266 --str.len;
@@ -1268,7 +1273,10 @@ ST_FUNC void parse_define(void) · 6 unmodified lines
1268 tok_str_add2(&str, tok, &tokc);1273 tok_str_add2(&str, tok, &tokc);
1269 skip:1274 skip:
1270 next_nomacro_spc();1275 next_nomacro_spc();
1276 macro_list_start = 0;
1271 }1277 }
1278 if (ptok == TOK_TWOSHARPS)
1279 tcc_error("'##' invalid at end of macro");
1272 if (spc == 1)1280 if (spc == 1)
1273 --str.len; /* remove trailing space */1281 --str.len; /* remove trailing space */
1274 tok_str_add(&str, 0);1282 tok_str_add(&str, 0);
tests/tests2/65_macro_concat_start.c+2−0
@@ -0,0 +1,2 @@
1#define paste(A,B) ##A B
2paste(x,y)
tests/tests2/65_macro_concat_start.expect+1−0
@@ -0,0 +1 @@
165_macro_concat_start.c:1: error: '##' invalid at start of macro
tests/tests2/66_macro_concat_end.c+2−0
@@ -0,0 +1,2 @@
1#define paste(A,B) A B##
2paste(x,y)
tests/tests2/66_macro_concat_end.expect+1−0
@@ -0,0 +1 @@
166_macro_concat_end.c:2: error: '##' invalid at end of macro
tests/tests2/Makefile+3−1
@@ -79,7 +79,9 @@ TESTS = \ · 78 unmodified lines
79 61_undefined_enum.test \79 61_undefined_enum.test \
80 62_enumerator_redefinition.test \80 62_enumerator_redefinition.test \
81 63_local_enumerator_redefinition.test \81 63_local_enumerator_redefinition.test \
82 64_macro_nesting.test82 64_macro_nesting.test \
83 65_macro_concat_start.test \
84 66_macro_concat_end.test
83 85
84# 30_hanoi.test -- seg fault in the code, gcc as well86# 30_hanoi.test -- seg fault in the code, gcc as well
85# 34_array_assignment.test -- array assignment is not in C standard87# 34_array_assignment.test -- array assignment is not in C standard

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