From patchwork Wed Oct 12 16:27:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1960 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp2699384wrs; Wed, 12 Oct 2022 09:28:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5+AyFcoQ+Vgk9ZXFXRnd7pL4K0Bhr5RKJOPKMv+MzwavM+Kln9L6sdQel83SkXwgVA+DQb X-Received: by 2002:a05:6402:5409:b0:44f:1e05:1e8 with SMTP id ev9-20020a056402540900b0044f1e0501e8mr28304402edb.373.1665592104520; Wed, 12 Oct 2022 09:28:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665592104; cv=none; d=google.com; s=arc-20160816; b=Sf//Cdf/nx8qpo7Eh17dXhUBOcPVNBxWtGTvJWSCPRCvtKwBjVv6zIzUlxx6Rs29ui 7JRglV9a55Iv3EJz8ZBizvQZwgqLXSRj+d+RqM/f646k83lZgIAufIBHeAAYe+WXqbbx EymiNrNl7mzrAaNp9jfclrATiMs9SsjEghb1YE2p+jr7DbA1lMHa+Zi3kFA3OHlOOgLb qtn3ZUcpijpsM/7pFVYhnD9kIMyWdS6L/l9HcGfLVp63mquLJ2uTbI68an6F6QBR+1Ow iDteYy9J1dwu5ZSRgD1Cd2ajy6TQ1peajxBLxqF5NgJWSWvbJzHnbdOTL0oOXDh9As8k bchg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:user-agent:in-reply-to:mime-version:references :message-id:subject:to:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=I6DSRwh9y8cZsdSuEXnYdmQqb/+7EzqoNgmVJPZ7CeQ=; b=JaKcsESOLenIKSaU4xG2337Mcp7QIMq6lakhLqH1qDTti9x2eUaPvtg5wmDaL7CS39 pb0Hw7ezkTfQiPVWopsg325QXY1bayjxRIMMQ4oFx3u3uTENdAZxjTrQrY2WssN3URUj WZgOTYrtYg4xmulQQV9h1erZ5fmzR1oPp8ujR0vnsMXEB8NiZwHvMy4k0DkqMz6Uu8uf Bhhxp1zy8tNbLXzCO1X4VYftXeqibO/+OzoJvEwioasacPK2MXGc/bviDbhXlvWmUAAL RaDMLpilDOGD4xGCMDRrsrQ91jurEd5ybfeG6HIpKeZXEV/6qrp5+xTunImKW/c7vvaR M/+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="w/CSFNdf"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id l16-20020a170906795000b007417040d1c5si16175011ejo.823.2022.10.12.09.28.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Oct 2022 09:28:24 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="w/CSFNdf"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 83D79385276B for ; Wed, 12 Oct 2022 16:28:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 83D79385276B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665592103; bh=I6DSRwh9y8cZsdSuEXnYdmQqb/+7EzqoNgmVJPZ7CeQ=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=w/CSFNdfaAxaogYQTNph1BPSy8VKf7TCq857pkCBmXqAOvQQGdMoKuakVwvJAs0od ViK69RjjOu0rYkLP4SGUSQ/HFGx9SVf+3S+1f+EvCYKBpIZGofnBVn3CSezPJbvZ0C bX9V1YWAl6NLklOvefQkNh6nlFoHP0l21etwJh5A= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id A3DB53858401 for ; Wed, 12 Oct 2022 16:27:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A3DB53858401 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.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-522-kTLjIqNcNgiFkqGB88VxUQ-1; Wed, 12 Oct 2022 12:27:39 -0400 X-MC-Unique: kTLjIqNcNgiFkqGB88VxUQ-1 Received: by mail-qk1-f199.google.com with SMTP id az32-20020a05620a172000b006ee8ae138a7so3603284qkb.4 for ; Wed, 12 Oct 2022 09:27:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I6DSRwh9y8cZsdSuEXnYdmQqb/+7EzqoNgmVJPZ7CeQ=; b=Bwe33ynSzA8OmbfTO/XzZR6ujjJ9/HPGCgoEoRzSnVNigYxZXahBKuix7Gud+LC9vB f+flczEReyloDeUSiQZ9MN6nz1mje/9jw/7IEyzIvwoGjoA8l5gye9dLogjXnouH4qhQ sw2wBn3IOCGo8TVhhk2HwhNDohzPzdjdO9vPMVbEMFmLWGjZIPJpLQ2SIVVgM53aomY3 i1A4+lwjYusGzy2qcfFcr9VohlvIgYYa+QZohJXKTgGXwU8nuw6fvhYMgJzFN7iD2Qf3 8dsgc+BaSt3HyVrKwE5KkH8cFMPPFR9jXeijlBs2BQ62cLBr3Q8obKn08xaMKdqGukCK NbfA== X-Gm-Message-State: ACrzQf2BSQ00/eAGzGbSMSMg9Ko8k1B7Yk0fGDnrrj4FJlRlbfDTqoIF Thwpc42l4OEeDHScybdz8CKU8ORH3YnSeRLSbu+BImH+b33KlWZdgxOMCIAncTZ5d8fIWZg7+Ld Vj1AeD0EmEvwlmf0IFA== X-Received: by 2002:ad4:574f:0:b0:4af:b3ed:8b9b with SMTP id q15-20020ad4574f000000b004afb3ed8b9bmr24143291qvx.1.1665592057984; Wed, 12 Oct 2022 09:27:37 -0700 (PDT) X-Received: by 2002:ad4:574f:0:b0:4af:b3ed:8b9b with SMTP id q15-20020ad4574f000000b004afb3ed8b9bmr24143271qvx.1.1665592057648; Wed, 12 Oct 2022 09:27:37 -0700 (PDT) Received: from redhat.com (2603-7000-9500-2e39-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:2e39::1db4]) by smtp.gmail.com with ESMTPSA id o8-20020ac841c8000000b00398313f286dsm9771924qtm.40.2022.10.12.09.27.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Oct 2022 09:27:36 -0700 (PDT) Date: Wed, 12 Oct 2022 12:27:34 -0400 To: Jason Merrill Subject: [PATCH v2] c++: ICE with VEC_INIT_EXPR and defarg [PR106925] Message-ID: References: <20221011200003.695682-1-polacek@redhat.com> <778ca670-6623-77f9-e941-51302007da64@redhat.com> MIME-Version: 1.0 In-Reply-To: <778ca670-6623-77f9-e941-51302007da64@redhat.com> User-Agent: Mutt/2.2.7 (2022-08-07) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 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: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek Cc: GCC Patches 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?1746422681079847110?= X-GMAIL-MSGID: =?utf-8?q?1746499906955029081?= 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). */ 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 >>> 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. > 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 base-commit: fbf423309e103b54f7c9d39b2f7870b9bedfe9d2 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>());