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.133.124]) by sourceware.org (Postfix) with ESMTPS id 4CF27385DC2D for ; Thu, 2 Jun 2022 20:26:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4CF27385DC2D Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-670-oowxbuzCMVe42qLU-b5H5w-1; Thu, 02 Jun 2022 16:26:30 -0400 X-MC-Unique: oowxbuzCMVe42qLU-b5H5w-1 Received: by mail-qk1-f199.google.com with SMTP id j12-20020ae9c20c000000b0069e8ac6b244so4516054qkg.1 for ; Thu, 02 Jun 2022 13:26:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=GPj+2dD+X7V07B3zwppWnuC3sFgidsEim0eiLuVF9g0=; b=1k/Cva4zdNeqWV+MTU0pi3ic3tsgnjyHPGqkvpKc/8LBzmRu8zOt5gX+FPaBq3/wji yFTdPg/SK1llgmNXj00afDRAJNHHVm2uoje0QE6i5Yvh4VbN9f87pgyx0nVXuXAW0bnL JoyRQo4KZFlUTtfzNOKZXO/BQplYZekEwzdF/Glzuew+I0i1FRb4GqljU77D2VrQi7/F AOvau21TkvV7hgGm38wpNKQZKctImToaE/ZZQ4lwSome1DG/Ulrc/KgFM+oYO7kmS0T3 Dctn6Q0P6vHpcui4f91KgHbvPSKsUB+wGTI32Bcv9Nt67ewMFso6Idy55mNl9fgI260Z WHdw== X-Gm-Message-State: AOAM532yGiEsGA0L/bVV4wv+FZlpJ190lTzCoNYNyeufhq66HVmYI5M3 X97qMH9qAR+ojfjwVKw3L8jw4GDs5aRYIaN0CH6VrV+3JfkUs4wdEgpKTzx0H36k+1h8hxTk8hZ NVJDzzYPLxACSa47stg== X-Received: by 2002:a05:622a:118f:b0:2f9:2187:c9d with SMTP id m15-20020a05622a118f00b002f921870c9dmr5046483qtk.538.1654201589503; Thu, 02 Jun 2022 13:26:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzp4ayB0Li5c/zDEqSY79qFqTGLdBqt3sHwc2syFp7bh0BK6kXt/5JK7gwupO1RdQ1HnEM5cA== X-Received: by 2002:a05:622a:118f:b0:2f9:2187:c9d with SMTP id m15-20020a05622a118f00b002f921870c9dmr5046465qtk.538.1654201589071; Thu, 02 Jun 2022 13:26:29 -0700 (PDT) Received: from [192.168.1.100] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id d127-20020a37b485000000b0069fc13ce257sm3785899qkf.136.2022.06.02.13.26.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 Jun 2022 13:26:28 -0700 (PDT) Message-ID: Date: Thu, 2 Jun 2022 16:26:27 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH] c++: ICE with template NEW_EXPR [PR105803] To: Marek Polacek Cc: Patrick Palka , GCC Patches References: <20220601224536.1553412-1-polacek@redhat.com> <68b3a5ff-698d-e680-6c94-b9aa5b7f3127@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, 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: Thu, 02 Jun 2022 20:26:32 -0000 On 6/2/22 16:10, Marek Polacek wrote: > On Thu, Jun 02, 2022 at 03:42:15PM -0400, Jason Merrill wrote: >> On 6/2/22 10:03, Marek Polacek wrote: >>> On Thu, Jun 02, 2022 at 08:42:36AM -0400, Patrick Palka wrote: >>>> On Wed, 1 Jun 2022, Marek Polacek via Gcc-patches wrote: >>>> >>>>> Here we ICE because value_dependent_expression_p gets a NEW_EXPR >>>>> whose operand is a type, and we go to the default case which just >>>>> calls v_d_e_p on each operand of the NEW_EXPR. Since one of them >>>>> is a type, we crash on the new assert in t_d_e_p. >>>> >>>> Looks like NEW_EXPR is considered to be not potentially constant >>>> according to potential_constant_expression. I thought we shouldn't >>>> be calling value_dependent_expression_p on such exprs? >> >> Except in C++20 new-expressions are potentially constant, so the patch is > > Thanks, pushed. > >> OK, and we should adjust pce1 accordingly. > > Is the attached patch OK then? So far dg.exp passed. Though it won't help > with... > >> I notice we currently fail to handle >> >> struct A >> { >> int i; >> constexpr A(int *p): i(*p) { delete p; } >> }; >> >> constexpr int i = A(new int(42)).i; >> >> though it does work inside a function. > > ...this test (it complains about a TARGET_EXPR's slot variable not being > declared constexpr), so I'm going to open a PR. > > From cf70354894bc31cc542ed8df40633bea2427fee7 Mon Sep 17 00:00:00 2001 > From: Marek Polacek > Date: Thu, 2 Jun 2022 15:56:18 -0400 > Subject: [PATCH] c++: new-expression is potentially constant in C++20 > > ... so adjust p_c_e accordingly. > > gcc/cp/ChangeLog: > > * constexpr.cc (potential_constant_expression_1): Treat > {,VEC_}NEW_EXPR as potentially constant in C++20. > --- > gcc/cp/constexpr.cc | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc > index 1346a1d4c10..2bbd8785627 100644 > --- a/gcc/cp/constexpr.cc > +++ b/gcc/cp/constexpr.cc > @@ -9039,10 +9039,18 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, > "before C++17"); > return false; > > - case DYNAMIC_CAST_EXPR: > - case PSEUDO_DTOR_EXPR: > case NEW_EXPR: > case VEC_NEW_EXPR: > + if (cxx_dialect >= cxx20) > + /* In C++20, new-expressions are potentially constant. */ > + return true; > + else if (flags & tf_error) > + error_at (loc, "new-expression is not a constant expression " > + "before C++20"); > + return false; > + > + case DYNAMIC_CAST_EXPR: > + case PSEUDO_DTOR_EXPR: > case DELETE_EXPR: > case VEC_DELETE_EXPR: Delete, too. > case THROW_EXPR: > > base-commit: 7b98910406b5000a6429c188b0c6cc14e3140637