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 8663438560A8 for ; Thu, 2 Jun 2022 19:42:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8663438560A8 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-84-lW3jo5C2Pd2UXoj3PbpaUA-1; Thu, 02 Jun 2022 15:42:18 -0400 X-MC-Unique: lW3jo5C2Pd2UXoj3PbpaUA-1 Received: by mail-qt1-f197.google.com with SMTP id c1-20020ac81101000000b002f9219952f0so4393386qtj.15 for ; Thu, 02 Jun 2022 12:42:18 -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=geSKvtv9yhgUj8aua6imLv8Nkir0Z1kUAXwdObymjDA=; b=rD75aLtBCW2/8qLksB5ANQaxlj9rinAMeqQHN3xs8fxbjO6lj+wa1umgtZByQh+qhk H9gIIKYxhvBdo86dSrg+M/qyyVArlbzzHy6w1NO7t0jdtRxal7tqIeg5UOpvjFVdbYdl FqpURMR6cQlk33t6nSFTSgJXQ419NxMtNFKusOauVktX+NYusc8WFGcDQnJ8tb0JbHXk jYRM19+JykJPaYrNG/sHH93B8VYI+1XHzH8y2mMy+QHmDkcSTchMSbNk7aVSFxRCo2Bc 4LcTVzazE+eJC5dtJIE16KMqO/hlDOtzWQ11+KboCfPKdacTzlgQbhH54GYl4I93oMyo IpHg== X-Gm-Message-State: AOAM5318yyncZkSY655E3KH/ZWbPUTZxuhBVGIVU1nQ+Zq2V30A7cPXU xKjUXvtOaPzw/zOjz3tEmAAnSV/zGsvAckL9DH7PPqelvsKzaBv1OrH9Y4l6fnSnr3mNR5IdVlb T5p5ocofDfFm8Yau+4A== X-Received: by 2002:ac8:57cc:0:b0:304:b904:a2e8 with SMTP id w12-20020ac857cc000000b00304b904a2e8mr5011653qta.472.1654198937891; Thu, 02 Jun 2022 12:42:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx55qOW4ORzHrgcD2JGK0/0Q1LrfA4Fk4RVIkyLtw+PdbOyCD3jmx3xlLXEA6m1USe/ZP7ttw== X-Received: by 2002:ac8:57cc:0:b0:304:b904:a2e8 with SMTP id w12-20020ac857cc000000b00304b904a2e8mr5011641qta.472.1654198937493; Thu, 02 Jun 2022 12:42:17 -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 z15-20020ac875cf000000b00301729af618sm3290738qtq.97.2022.06.02.12.42.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 Jun 2022 12:42:16 -0700 (PDT) Message-ID: <68b3a5ff-698d-e680-6c94-b9aa5b7f3127@redhat.com> Date: Thu, 2 Jun 2022 15:42:15 -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 , Patrick Palka Cc: GCC Patches References: <20220601224536.1553412-1-polacek@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=-7.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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 19:42:21 -0000 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 OK, and we should adjust pce1 accordingly. 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. > You're correct. This is non-obvious: instantiation_dependent_expression_p > calls p_c_e before v_d_e_p, but the expression is CAST_EXPR<[NEW_EXPR]>, > where the [] denotes a TREE_LIST, created in cp_parser_functional_cast. > This TREE_LIST has no type. So p_c_e_1/CAST_EXPR goes to > 9183 /* If this is a dependent type, it could end up being a class > 9184 with conversions. */ > 9185 if (type == NULL_TREE || WILDCARD_TYPE_P (type)) > 9186 return true; > and returns true. > > So we call v_d_e_p, which looks at the CAST_EXPR's op and sees a TREE_LIST, > so it calls any_value_dependent_elements_p, and we end up with a NEW_EXPR. > > An alternative/more proper fix would be to fix p_c_e_1/CAST_EXPR. Maybe > by calling any_type_dependent_elements_p (which currently has no uses). > Thoughts? > >>> --- /dev/null >>> +++ b/gcc/testsuite/g++.dg/template/new13.C >>> @@ -0,0 +1,11 @@ >>> +// PR c++/105803 >>> +// { dg-do compile } >>> +// { dg-additional-options "-fchecking=2" } >>> + >>> +namespace std { >>> +template class shared_ptr; >>> +} >>> +struct S {}; >>> +template void build_matrices() { >>> + std::shared_ptr(new S); >>> +} >> >> I think this testcase might be IFNDR since shared_ptr is incomplete >> at the point of its non-dependent use. > > Ah, overreduced. I've made shared_ptr complete. > > Marek >