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 325C53858000 for ; Wed, 21 Dec 2022 21:48:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 325C53858000 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=1671659312; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/axjRIEx7InBT2W03YaZVfHv8tCBJQ8RmBUr0QTmuZw=; b=IEws05oIXyb583m8EWEadXA0KbBEeYp1tkEiZQTdkOmRTUK/wJjxV+v0jZ3VdXX9iIOLhc VPV+3n8Zu9rLKHjtzxla8zsdytE+9d87TVLEb4Qhklp8u1TxhSafkWqUM1v6OFvnwYbnSO UhrP9EoHfcR8ERuoy3dSyAAChnXIQmg= 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-48-jtXYoLo4NvGLBmuELdzGTg-1; Wed, 21 Dec 2022 16:48:31 -0500 X-MC-Unique: jtXYoLo4NvGLBmuELdzGTg-1 Received: by mail-qk1-f199.google.com with SMTP id bl3-20020a05620a1a8300b0070240ff36a0so8323393qkb.19 for ; Wed, 21 Dec 2022 13:48:31 -0800 (PST) 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: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=/axjRIEx7InBT2W03YaZVfHv8tCBJQ8RmBUr0QTmuZw=; b=KZwJrXpEtZAywXd2Dk397smzd4cgHa3xUQHXsPWfWOHWqlWqMaeHteardAQK6tc990 SMD0GgGeMJSeWpGIE66GbXdnC08WNpyKzkS/26IhqfO7MvFtjv9qZeR/M+KON2cEexpC zRsbfipHAD4y0aFkiIoLU6rGGx6J6MmXReSrpfOWlyi/u0PbjJaBKConjJA28+h9C6Cs YHDNosqV+pvcOHK50PLgu8ClSETjVmrs1YZ1kk6WzAjlJ2vC4jYgBVa3aDcyh2cfmlMD 8eSQZkh8UrapBb3OqdisGRQjl64HTDu+r1KAW7FLHQULSAmjqVwdvNRiU7SNzWnGfets qIlw== X-Gm-Message-State: AFqh2kplqXwSUzXEw5mZ+eJAIBIU1oF6k8e288P+VzkLV474CQRObdbn 3yCh19JulmqQ6k7S70nrVEoXulc2h/drbcsHOfOWugbs+mKMZYE1IeHElw+13KLTCslofH3eEH1 w+47Qw2pXhqDVJaMhUQ== X-Received: by 2002:a05:622a:1e95:b0:3a7:f93a:df8 with SMTP id bz21-20020a05622a1e9500b003a7f93a0df8mr4210007qtb.61.1671659311073; Wed, 21 Dec 2022 13:48:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXsNN58oJcKLKaBJm1owXK8202wZGUmrNY0JieUqpo2wIc2OezrBVpw91MsgQOLOEUDJmLvw6A== X-Received: by 2002:a05:622a:1e95:b0:3a7:f93a:df8 with SMTP id bz21-20020a05622a1e9500b003a7f93a0df8mr4209973qtb.61.1671659310614; Wed, 21 Dec 2022 13:48:30 -0800 (PST) Received: from [192.168.1.108] (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 v18-20020a05620a0f1200b006cf38fd659asm11900030qkl.103.2022.12.21.13.48.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 21 Dec 2022 13:48:29 -0800 (PST) Message-ID: Date: Wed, 21 Dec 2022 16:48:28 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH] c++: get_nsdmi in template context [PR108116] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20221221145254.389983-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20221221145254.389983-1-ppalka@redhat.com> 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.0 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,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 List-Id: On 12/21/22 09:52, Patrick Palka wrote: > Here during ahead of time checking of C{}, we indirectly call get_nsdmi > for C::m from finish_compound_literal, which in turn calls > break_out_target_exprs for C::m's (non-templated) initializer, during > which we end up building a call to A::~A and checking expr_noexcept_p > for it (from build_vec_delete_1). But this is all done with > processing_template_decl set, so the built A::~A call is templated > (whose form r12-6897-gdec8d0e5fa00ceb2 recently changed) which > expr_noexcept_p doesn't expect and we crash. > > In r10-6183-g20afdcd3698275 we fixed a similar issue by guarding a > expr_noexcept_p call with !processing_template_decl, which works here > too. But it seems to me since the initializer we obtain in get_nsdmi is > always non-templated, it should be calling break_out_target_exprs with > processing_template_decl cleared since otherwise the function might end > up mixing templated and non-templated trees. > > I'm not sure about this though, perhaps this is not the best fix here. > Alternatively, when processing_template_decl we could make get_nsdmi > avoid calling break_out_target_exprs at all or something. Additionally, > perhaps break_out_target_exprs should be a no-op more generally when > processing_template_decl since we shouldn't see any TARGET_EXPRs inside > a template? Hmm. Any time we would call break_out_target_exprs we're dealing with non-dependent expressions; if we're in a template, we're building up an initializer or a call that we'll soon throw away, just for the purpose of checking or type computation. Furthermore, as you say, the argument is always a non-template tree, whether in get_nsdmi or convert_default_arg. So having processing_template_decl cleared would be correct. I don't think we can get away with not calling break_out_target_exprs at all in a template; if nothing else, we would lose immediate invocation expansion. However, we could probably skip the bot_manip tree walk, which should avoid the problem. Either way we end up returning non-template trees, as we do now, and callers have to deal with transient CONSTRUCTORs containing such (as we do in massage_init_elt). Does convert_default_arg not run into the same problem, e.g. when calling void g(B = {0}); ? > Bootstrapped and regtested on x86_64-pc-linux-gnu. > > PR c++/108116 > > gcc/cp/ChangeLog: > > * init.cc (get_nsdmi): Clear processing_template_decl before > processing the non-templated initializer. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp0x/nsdmi-template24.C: New test. > --- > gcc/cp/init.cc | 8 ++++++- > gcc/testsuite/g++.dg/cpp0x/nsdmi-template24.C | 22 +++++++++++++++++++ > 2 files changed, 29 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/cpp0x/nsdmi-template24.C > > diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc > index 73e6547c076..c4345ebdaea 100644 > --- a/gcc/cp/init.cc > +++ b/gcc/cp/init.cc > @@ -561,7 +561,8 @@ perform_target_ctor (tree init) > return init; > } > > -/* Return the non-static data initializer for FIELD_DECL MEMBER. */ > +/* Return the non-static data initializer for FIELD_DECL MEMBER. > + The initializer returned is always non-templated. */ > > static GTY((cache)) decl_tree_cache_map *nsdmi_inst; > > @@ -670,6 +671,11 @@ get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain) > current_class_ptr = build_address (current_class_ref); > } > > + /* Since INIT is always non-templated clear processing_template_decl > + before processing it so that we don't interleave templated and > + non-templated trees. */ > + processing_template_decl_sentinel ptds; > + > /* Strip redundant TARGET_EXPR so we don't need to remap it, and > so the aggregate init code below will see a CONSTRUCTOR. */ > bool simple_target = (init && SIMPLE_TARGET_EXPR_P (init)); > diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template24.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template24.C > new file mode 100644 > index 00000000000..202c67d7321 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template24.C > @@ -0,0 +1,22 @@ > +// PR c++/108116 > +// { dg-do compile { target c++11 } } > + > +#include > + > +struct A { > + A(int); > + ~A(); > +}; > + > +struct B { > + B(std::initializer_list); > +}; > + > +struct C { > + B m{0}; > +}; > + > +template > +void f() { > + C c = C{}; > +};