mirror of
https://github.com/mirror/tinycc.git
synced 2024-12-28 04:00:06 +08:00
pp: Move errors about stray backslashes
they were emitted too early, in particular also in macro substitution which might turn out to not be stray in case it's further stringified. Check in next() instead. Add two testcases that an error is still emitted for obvious top-level baskslashes, and that stringifying such a thing works.
This commit is contained in:
parent
e640ed1aeb
commit
068d5b3d20
5
tccpp.c
5
tccpp.c
@ -3511,8 +3511,6 @@ static void macro_subst(
|
||||
if (tok_str->len)
|
||||
spc = is_space(t = tok_str->str[tok_str->lastlen]);
|
||||
} else {
|
||||
if (t == '\\' && !(parse_flags & PARSE_FLAG_ACCEPT_STRAYS))
|
||||
tcc_error("stray '\\' in program");
|
||||
no_subst:
|
||||
if (!check_space(t, &spc))
|
||||
tok_str_add2(tok_str, t, &cval);
|
||||
@ -3569,7 +3567,8 @@ ST_FUNC void next(void)
|
||||
} else if (tok == TOK_PPSTR) {
|
||||
if (parse_flags & PARSE_FLAG_TOK_STR)
|
||||
parse_string((char *)tokc.str.data, tokc.str.size - 1);
|
||||
}
|
||||
} else if (tok == '\\' && !(parse_flags & PARSE_FLAG_ACCEPT_STRAYS))
|
||||
tcc_error("stray '\\' in program");
|
||||
}
|
||||
|
||||
/* push back current token and set current token to 'last_tok'. Only
|
||||
|
@ -420,6 +420,9 @@ comment
|
||||
have_included_42test_h = 1;
|
||||
have_included_42test_h_second = 1;
|
||||
have_included_42test_h_third = 1;
|
||||
|
||||
/* Check that we don't complain about stray \ here */
|
||||
printf("print a backslash: %s\n", stringify(\\));
|
||||
}
|
||||
|
||||
|
||||
|
@ -318,5 +318,8 @@ int main()
|
||||
int n = _Generic(*a, double:0, long double:1);
|
||||
}
|
||||
|
||||
#elif defined test_stray_backslash
|
||||
#define x \a
|
||||
x
|
||||
/******************************************************************/
|
||||
#endif
|
||||
|
@ -150,3 +150,6 @@ bar : 3 ; 3
|
||||
|
||||
[test_long_double_type_for_win32]
|
||||
60_errors_and_warnings.c:317: warning: assignment from incompatible pointer type
|
||||
|
||||
[test_stray_backslash]
|
||||
60_errors_and_warnings.c:323: error: stray '\' in program
|
||||
|
Loading…
Reference in New Issue
Block a user