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 1B7543858D38 for ; Wed, 12 Oct 2022 16:47:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1B7543858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665593244; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s5T5EOYw9SR1OOTCAc27CPon/55ISGcaZuTBgIXHvh0=; b=LUThJZMSf7c3NEwlVZObvqNLuWBBcuB5Hd0Z8Hqi1JOo86o2fgEKLj29NlCVAW5uPg3wVX TbiZdAXy7pZxmarIuNeBO78pyVA/EKeW6WomymNhpsqthXRX/UvAfeaRySKKf2CK5lkG7B eLecCdLtkYt2SGipEfkUHTq9vcqlwmw= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-662-mrRD65q5N36uG9m_8YitgQ-1; Wed, 12 Oct 2022 12:47:23 -0400 X-MC-Unique: mrRD65q5N36uG9m_8YitgQ-1 Received: by mail-qv1-f69.google.com with SMTP id v3-20020a0cf903000000b004b4619bb7e3so2697310qvn.22 for ; Wed, 12 Oct 2022 09:47:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=s5T5EOYw9SR1OOTCAc27CPon/55ISGcaZuTBgIXHvh0=; b=aKFJOvM+7We9c1qt2akhO45UBTFfw/7K8Bkm7UCCbBj5vKfZ6fkYwCQGf88VQSHfMY 93BKUgmJKCxktVm5riCMvQ9tMtOvE4Bb5qMecDVIW6Dw2XJFKowCngpNfceqIiTw1bCR KcLUwITHHG1KH1rJ8QhzjEeKGZo+vv82fqgDeCwMYAlRJjaNIk7p0sPiCZvcE3DaPsGt UwIbN3i6Fav2scbFFc5CumTWAAHeSX6Jei/riLs6/Z4ERTgJVhaYhSJvr4wOWcy4x3ES ZZWOprv0H2nMVmelyE/DB1NUMeO4Fg59+Hiuu6jvXZY+md9OFeg03Lc3BoTLnxmpHxJo W3pw== X-Gm-Message-State: ACrzQf2Vx+Cn76wqeOgdxqE6P3wFz/qh8SjqcCofGFlAPyNEsouoXE8y sRFGuFxDGZ+U2n5lwAUUaOb4dPH283ORyspqG5YhmAzNE18iZG3ZECqezrBh3sWoy4lr7HIZtHh Cp2LqBe1qQgoQlcEwdw== X-Received: by 2002:ac8:7dc7:0:b0:35c:c050:16aa with SMTP id c7-20020ac87dc7000000b0035cc05016aamr24375778qte.455.1665593243247; Wed, 12 Oct 2022 09:47:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM59YzTqMPiGUXm8GbRaCfqAoNABXAzvlSmQaK65evauPO/cMepSSKPddlbGncrVWsOE/7EFEg== X-Received: by 2002:ac8:7dc7:0:b0:35c:c050:16aa with SMTP id c7-20020ac87dc7000000b0035cc05016aamr24375751qte.455.1665593242901; Wed, 12 Oct 2022 09:47:22 -0700 (PDT) Received: from [192.168.1.101] (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 s22-20020ac85296000000b0039c7b9522ecsm3456536qtn.35.2022.10.12.09.47.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Oct 2022 09:47:22 -0700 (PDT) Message-ID: Date: Wed, 12 Oct 2022 12:47:21 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.2 Subject: Re: [PATCH v2] c++: ICE with VEC_INIT_EXPR and defarg [PR106925] To: Marek Polacek Cc: GCC Patches References: <20221011200003.695682-1-polacek@redhat.com> <778ca670-6623-77f9-e941-51302007da64@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=-12.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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 10/12/22 12:27, Marek Polacek wrote: > On Tue, Oct 11, 2022 at 04:28:11PM -0400, Jason Merrill wrote: >> On 10/11/22 16:00, Marek Polacek wrote: >>> Since r12-8066, in cxx_eval_vec_init we perform expand_vec_init_expr >>> while processing the default argument in this test. >> >> Hmm, why are we calling cxx_eval_vec_init during parsing of the default >> argument? In particular, any expansion that depends on the enclosing >> function context should be deferred until the default arg is used by a call. > > I think this is part of the semantic constraints checking [dcl.fct.default]/5 > talks about, as in, this doesn't compile even though the default argument is > not executed: > > struct S { > S() = delete; > }; > void foo (S = S()) { } > > In the test below we parse '= MyVector<1>()' and end up calling mark_used > on the implicit "constexpr MyVector<1>::MyVector() noexcept ()" > ctor. mark_used calls maybe_instantiate_noexcept. Since the ctor has > a DEFERRED_NOEXCEPT, we have to figure out if the ctor should be noexcept > or not using get_defaulted_eh_spec. That means walking the members of > MyVector. Thus we reach > /* Core 1351: If the field has an NSDMI that could throw, the > default constructor is noexcept(false). */ Maybe we need a cp_unevaluated here? The operand of noexcept should be unevaluated. > and call get_nsdmi on 'data'. There we digest its initializer which is {}. > massage_init_elt calls digest_init_r on the {} and produces > TARGET_EXPR D.2518 > {} >>>> > and the subsequent fold_non_dependent_init leads to cxx_eval_vec_init > -> expand_vec_init_expr. > > I think this is all correct except that the fold_non_dependent_init is > somewhat questionable to me; do we really have to fold in order to say > if the NSDMI init can throw? Sure, we need to digest the {}, maybe > the field's ctors can throw, but I don't know about the folding. And we can check cp_unevaluated_operand to avoid the fold_non_dependent_init? >> But it's certainly true that the "function_body" test is wrong in this >> situation; you might move the c_f_d test into the calculation of that >> variable. The patch is OK with that change, but please also answer my >> question above. > > I like that. Before I go ahead and apply, please let me know if the answer > above is satisfying. > > -- >8 -- > Since r12-8066, in cxx_eval_vec_init we perform expand_vec_init_expr > while processing the default argument in this test. At this point > start_preparsed_function hasn't yet set current_function_decl. > expand_vec_init_expr then leads to maybe_splice_retval_cleanup which > checks DECL_CONSTRUCTOR_P (current_function_decl) without checking that > c_f_d is non-null first. It seems correct that c_f_d is null here, so > it seems to me that maybe_splice_retval_cleanup should check c_f_d as > in the following patch. > > PR c++/106925 > > gcc/cp/ChangeLog: > > * except.cc (maybe_splice_retval_cleanup): Check current_function_decl. > Make the bool const. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp0x/initlist-defarg3.C: New test. > --- > gcc/cp/except.cc | 7 +++++-- > gcc/testsuite/g++.dg/cpp0x/initlist-defarg3.C | 13 +++++++++++++ > 2 files changed, 18 insertions(+), 2 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-defarg3.C > > diff --git a/gcc/cp/except.cc b/gcc/cp/except.cc > index b8a85ed0572..a9114a5f7a5 100644 > --- a/gcc/cp/except.cc > +++ b/gcc/cp/except.cc > @@ -1322,9 +1322,12 @@ maybe_splice_retval_cleanup (tree compound_stmt) > { > /* If we need a cleanup for the return value, add it in at the same level as > pushdecl_outermost_localscope. And also in try blocks. */ > - bool function_body > + const bool function_body > = (current_binding_level->level_chain > - && current_binding_level->level_chain->kind == sk_function_parms); > + && current_binding_level->level_chain->kind == sk_function_parms > + /* When we're processing a default argument, c_f_d may not have been > + set. */ > + && current_function_decl); > > if ((function_body || current_binding_level->kind == sk_try) > && !DECL_CONSTRUCTOR_P (current_function_decl) > diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-defarg3.C b/gcc/testsuite/g++.dg/cpp0x/initlist-defarg3.C > new file mode 100644 > index 00000000000..5c3e886b306 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-defarg3.C > @@ -0,0 +1,13 @@ > +// PR c++/106925 > +// { dg-do compile { target c++11 } } > + > +struct Foo; > +template struct __array_traits { typedef Foo _Type[_Nm]; }; > +template struct array { > + typename __array_traits<_Nm>::_Type _M_elems; > +}; > +template struct MyVector { array data{}; }; > +struct Foo { > + float a{0}; > +}; > +void foo(MyVector<1> = MyVector<1>()); > > base-commit: fbf423309e103b54f7c9d39b2f7870b9bedfe9d2