From patchwork Thu Mar 30 07:47:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 76934 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp946930vqo; Thu, 30 Mar 2023 00:48:09 -0700 (PDT) X-Google-Smtp-Source: AKy350bVtzpzOQw6O5wi5MsnoSyRFDSCSBMa14frCV+9qOWcfTeybrAuWcTx1cpH6aM7rDzwV0OJ X-Received: by 2002:a05:6402:653:b0:4fb:e9b8:ca56 with SMTP id u19-20020a056402065300b004fbe9b8ca56mr18809949edx.41.1680162489665; Thu, 30 Mar 2023 00:48:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680162489; cv=none; d=google.com; s=arc-20160816; b=jPZIIZL1j4G68gG4khkpFF375ZPCLoRD9vSyCTiBMFBeD9r/CYn6GvDekCe39MAZf8 saSKDSezBRDk96bIhmPprnX3GANFX6+49RQ9hrQHLBAUrbaVdtxUeTJ3AZakRheLzAdi MShqfPl0Gz0XXE0O2+qFhtfQlnGoAeLTlgEWVoRFDqCw5buB6GP/2Vun1gyRwiJySqgc BaKURc6Atu1GXkq3didf+FEO6FeqCIPYVoJlMud5iYlddH3nI25+LZifLTCg0uMXmgDr Th9oZz3Q/73HGQlOV2d+QknTsIhg32NoJSeuqYLg9AsZt97zEBECV9ZXbtWq5np6SrVr 8ROg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Ejsdun2LMsScrHYRy3gLlMU28bw4V8vRrscUrEWr0H4=; b=JLj4yITsLz3/XalROau7HsRrwzfZew+Zd4BCUv0IlYlapcqXCTcEpAbKf/wB1V7wF/ vgCWBsxD3nTDBPxZIhkf7RDmQvqmPHPegnEKXNLhCBCB2TEDH+lqMBkrnrSl2wfEi8OF C3O7W5189YTjmknULGp6dEani0OzcKSVumhA+50AVxSjqufMYpZyFrZuPz8Yl3LvNsGW ID69ICixJr65eeNIFBG0RWSbZ54Pqle1IhS0XS7HRDMBrisQZcJt6yhDmD5tikuICWs9 uHlUYZhTR+Qm4PgiTXGyPBmwp1t/6QtgA+hpqBdvkQ5RUVf5NG6zJx7kB/2NmLkN61B7 AYww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cSVgALgQ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id l8-20020aa7c3c8000000b0050232b70cebsi14507662edr.648.2023.03.30.00.48.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 00:48:09 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cSVgALgQ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 522413858CDA for ; Thu, 30 Mar 2023 07:48:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 522413858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680162488; bh=Ejsdun2LMsScrHYRy3gLlMU28bw4V8vRrscUrEWr0H4=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=cSVgALgQ8WRHendk4NwmBYlnhmjYi9OkWscMT0i98ovPTPCYt2PymP1IYE30Lj03n aQdFwd/yAulFExP3w4taHIm2tRREL1unqSaWJwHd1iUkeDZ8oEuMwJ7KGk2AgxK+Wr 6mbbdXPz58T0qqEUpr1zB3yocm+dQ9m4PIzK6Hhg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 459FD3858CDA for ; Thu, 30 Mar 2023 07:47:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 459FD3858CDA Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-645-gsESj8y4MuGf1CW1HTR9bg-1; Thu, 30 Mar 2023 03:47:22 -0400 X-MC-Unique: gsESj8y4MuGf1CW1HTR9bg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 18FBA280D580 for ; Thu, 30 Mar 2023 07:47:22 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C00E418EC6; Thu, 30 Mar 2023 07:47:21 +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 32U7lJVH1700214 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 30 Mar 2023 09:47:19 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 32U7lID41700213; Thu, 30 Mar 2023 09:47:18 +0200 Date: Thu, 30 Mar 2023 09:47:18 +0200 To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix up ICE in build_min_non_dep_op_overload [PR109319] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761778062458273867?= X-GMAIL-MSGID: =?utf-8?q?1761778062458273867?= Hi! The following testcase ICEs, because grok_array_decl during processing_template_decl handling of a non-dependent subscript emits a -Wcomma-subscript pedwarn, we decide to pass to the single index argument the index expressions as if it was wrapped with () around it, but then when preparing it for later instantiation we don't actually take that into account and ICE on a mismatch of number of index arguments (the overload expects a single index, testcase has two index expressions in this case). For non-dependent subscript which are builtin subscripts we also emit the same pedwarn and don't ICE, but emit the same pedwarn again whenever we instantiate it, which is also IMHO undesirable, it is enough to warn once during parsing the template. The following patch fixes it by turning even the original index expressions (those which didn't go through make_args_non_dependent) into a single index using comma expression(s). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-03-30 Jakub Jelinek PR c++/109319 * decl2.cc (grok_array_decl): After emitting a pedwarn for -Wcomma-subscript, if processing_template_decl set orig_index_exp to compound expr from orig_index_exp_list. * g++.dg/cpp23/subscript14.C: New test. Jakub --- gcc/cp/decl2.cc.jj 2023-03-20 20:29:34.000000000 +0100 +++ gcc/cp/decl2.cc 2023-03-29 15:17:14.952173134 +0200 @@ -474,11 +474,23 @@ grok_array_decl (location_t loc, tree ar &overload, complain); } else - /* If it would be valid albeit deprecated expression in C++20, - just pedwarn on it and treat it as if wrapped in (). */ - pedwarn (loc, OPT_Wcomma_subscript, - "top-level comma expression in array subscript " - "changed meaning in C++23"); + { + /* If it would be valid albeit deprecated expression in + C++20, just pedwarn on it and treat it as if wrapped + in (). */ + pedwarn (loc, OPT_Wcomma_subscript, + "top-level comma expression in array subscript " + "changed meaning in C++23"); + if (processing_template_decl) + { + orig_index_exp + = build_x_compound_expr_from_vec (orig_index_exp_list, + NULL, complain); + if (orig_index_exp == error_mark_node) + expr = error_mark_node; + release_tree_vector (orig_index_exp_list); + } + } } } } @@ -519,6 +531,15 @@ grok_array_decl (location_t loc, tree ar return error_mark_node; } index_exp = idx; + if (processing_template_decl) + { + orig_index_exp + = build_x_compound_expr_from_vec (orig_index_exp_list, + NULL, complain); + release_tree_vector (orig_index_exp_list); + if (orig_index_exp == error_mark_node) + return error_mark_node; + } } if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE) --- gcc/testsuite/g++.dg/cpp23/subscript14.C.jj 2023-03-29 15:29:46.037076158 +0200 +++ gcc/testsuite/g++.dg/cpp23/subscript14.C 2023-03-29 15:34:18.645051075 +0200 @@ -0,0 +1,42 @@ +// PR c++/109319 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +struct A { static int &operator[] (int x) { static int a[2]; return a[x]; } }; // { dg-warning "may be a static member function only with" "" { target c++20_down } } +struct B { int &operator[] (int x) { static int b[2]; return b[x]; } }; +int c[2]; + +template +int +foo () +{ + A a; + ++a[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } } + B b; // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 } + ++b[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } } + // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 } + ++c[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } } + T d; // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 } + ++d[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } } + U e; // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 } + ++e[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } } + extern V f[2]; // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 } + ++f[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } } + return 0; // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 } +} + +int f[2]; + +int +main () +{ + A a; + ++a[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } } + B b; // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 } + ++b[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } } + // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 } + ++c[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } } + foo (); // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 } + if (a.operator[] (1) != 3 || b.operator[] (1) != 3 || c[1] != 2 || f[1] != 1) + __builtin_abort (); +}