diff options
author | Jakub Jelinek <jakub@redhat.com> | 2022-05-29 21:57:51 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2022-05-29 21:57:51 +0200 |
commit | 58a40e76ebadce78639644cd3d56e42b68336927 (patch) | |
tree | 4e9302c965b06758d9f1c25b197a1533ca3c7a1d | |
parent | 794737976b9a6418eab817f143bb4eb2d0c834d2 (diff) | |
download | gcc-58a40e76ebadce78639644cd3d56e42b68336927.zip gcc-58a40e76ebadce78639644cd3d56e42b68336927.tar.gz gcc-58a40e76ebadce78639644cd3d56e42b68336927.tar.bz2 |
libcpp: Ignore CPP_PADDING tokens in _cpp_parse_expr [PR105732]
The first part of the following testcase (m1-m3 macros and its use)
regressed with my PR89971 fix, but as the m1,m4-m5 and its use part shows,
the problem isn't new, we can emit a CPP_PADDING token to avoid it from
being adjacent to whatever comes after the __VA_OPT__ (in this case there
is nothing afterwards, true).
In most cases these CPP_PADDING tokens don't matter, all other
callers of cpp_get_token_with_location either ignore CPP_PADDING tokens
completely (e.g. c_lex_with_flags) or they just remember them and
take them into account when printing stuff whether there should be
added whitespace or not (scan_translation_unit + token_streamer::stream).
So, I think we should just ignore CPP_PADDING tokens the same way in
_cpp_parse_expr.
2022-05-27 Jakub Jelinek <jakub@redhat.com>
PR preprocessor/105732
* expr.cc (_cpp_parse_expr): Handle CPP_PADDING by just another
token.
* c-c++-common/cpp/va-opt-10.c: New test.
-rw-r--r-- | gcc/testsuite/c-c++-common/cpp/va-opt-10.c | 18 | ||||
-rw-r--r-- | libcpp/expr.cc | 4 |
2 files changed, 22 insertions, 0 deletions
diff --git a/gcc/testsuite/c-c++-common/cpp/va-opt-10.c b/gcc/testsuite/c-c++-common/cpp/va-opt-10.c new file mode 100644 index 0000000..f810b42 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/va-opt-10.c @@ -0,0 +1,18 @@ +/* PR preprocessor/105732 */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99" { target c } } */ +/* { dg-options "-std=c++20" { target c++ } } */ + +#define m1(p1, p2, p3) p3 +#define m2(p1, ...) 1##__VA_OPT__(foo) +#define m3(...) m1(1, 2, m2) +#define m4(p1, ...) 1 __VA_OPT__() +#define m5(...) m1(1, 2, m4) +#if m3(,)(,) +#else +#error +#endif +#if m5(,)(,) +#else +#error +#endif diff --git a/libcpp/expr.cc b/libcpp/expr.cc index 78c5c3e..a022904 100644 --- a/libcpp/expr.cc +++ b/libcpp/expr.cc @@ -1366,6 +1366,10 @@ _cpp_parse_expr (cpp_reader *pfile, bool is_if) op.op = CPP_UMINUS; break; + case CPP_PADDING: + lex_count--; + continue; + default: if ((int) op.op <= (int) CPP_EQ || (int) op.op >= (int) CPP_PLUS_EQ) SYNTAX_ERROR2_AT (op.loc, |