From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id CB1F9382CCAE for ; Fri, 27 May 2022 08:16:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CB1F9382CCAE Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-483-5T_MfWNHOLuHygNpSLT0kg-1; Fri, 27 May 2022 04:16:20 -0400 X-MC-Unique: 5T_MfWNHOLuHygNpSLT0kg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 11B68100BAA8; Fri, 27 May 2022 08:16:20 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.33.36.77]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C67134111481; Fri, 27 May 2022 08:16:19 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 24R8GHo41914940 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 27 May 2022 10:16:17 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 24R8GGst1914939; Fri, 27 May 2022 10:16:16 +0200 Date: Fri, 27 May 2022 10:16:16 +0200 From: Jakub Jelinek To: "Joseph S. Myers" , Marek Polacek , Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] libcpp: Ignore CPP_PADDING tokens in _cpp_parse_expr [PR105732] Message-ID: Reply-To: Jakub Jelinek MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 May 2022 08:16:25 -0000 Hi! 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. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-05-27 Jakub Jelinek 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. --- libcpp/expr.cc.jj 2022-01-18 11:59:00.258972399 +0100 +++ libcpp/expr.cc 2022-05-26 15:39:54.348780446 +0200 @@ -1366,6 +1366,10 @@ _cpp_parse_expr (cpp_reader *pfile, bool 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, --- gcc/testsuite/c-c++-common/cpp/va-opt-10.c.jj 2022-05-26 15:54:40.279766330 +0200 +++ gcc/testsuite/c-c++-common/cpp/va-opt-10.c 2022-05-26 15:54:24.028928687 +0200 @@ -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 Jakub