diff --git a/tccpp.c b/tccpp.c index c4c1ce53..1c2c8bc9 100644 --- a/tccpp.c +++ b/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 diff --git a/tests/tcctest.c b/tests/tcctest.c index 1c12dc31..a866330e 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -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(\\)); } diff --git a/tests/tests2/60_errors_and_warnings.c b/tests/tests2/60_errors_and_warnings.c index ac331ebb..19b7f0c1 100644 --- a/tests/tests2/60_errors_and_warnings.c +++ b/tests/tests2/60_errors_and_warnings.c @@ -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 diff --git a/tests/tests2/60_errors_and_warnings.expect b/tests/tests2/60_errors_and_warnings.expect index 838f6fcc..d693f91a 100644 --- a/tests/tests2/60_errors_and_warnings.expect +++ b/tests/tests2/60_errors_and_warnings.expect @@ -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