public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-10846] libcpp: Ignore CPP_PADDING tokens in _cpp_parse_expr [PR105732]
Date: Wed, 15 Jun 2022 12:06:12 +0000 (GMT)	[thread overview]
Message-ID: <20220615120612.19C71385734C@sourceware.org> (raw)

https://gcc.gnu.org/g:b2f5dc82400fe04511b85caa8c80677f81eee415

commit r10-10846-gb2f5dc82400fe04511b85caa8c80677f81eee415
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sun May 29 21:57:51 2022 +0200

    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.c (_cpp_parse_expr): Handle CPP_PADDING by just another
            token.
    
            * c-c++-common/cpp/va-opt-10.c: New test.
    
    (cherry picked from commit 58a40e76ebadce78639644cd3d56e42b68336927)

Diff:
---
 gcc/testsuite/c-c++-common/cpp/va-opt-10.c | 18 ++++++++++++++++++
 libcpp/expr.c                              |  4 ++++
 2 files changed, 22 insertions(+)

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 00000000000..f810b429dd6
--- /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.c b/libcpp/expr.c
index 2ae9be07c1a..634190d26d6 100644
--- a/libcpp/expr.c
+++ b/libcpp/expr.c
@@ -1340,6 +1340,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,


                 reply	other threads:[~2022-06-15 12:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220615120612.19C71385734C@sourceware.org \
    --to=jakub@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).