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 78C843858D1E for ; Wed, 21 Dec 2022 14:56:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 78C843858D1E 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=1671634579; 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: in-reply-to:in-reply-to:references:references; bh=ovBRjIXwZ70tlY+skCpeXAvAlxiaqxk455V7X3zOcy0=; b=cs5IMfDgu26QPp1hMPEAauGTVjq1Ws3+At+YnK1bX+9xnMpbQbuDYeK+roj06D0jZum+TJ pH7wvYALNmLFRLzO9XYBRmaIcOZ4tz+0RcVkFbtQdgpJXd2TyqvBZNnbo96dhq3mVgzZB0 AokVuE8yvn5TNlPt8eOoFGallsy9pfA= Received: from mail-yw1-f198.google.com (mail-yw1-f198.google.com [209.85.128.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-186-yjVPJYBNP2K-K_AtI1gwUA-1; Wed, 21 Dec 2022 09:56:17 -0500 X-MC-Unique: yjVPJYBNP2K-K_AtI1gwUA-1 Received: by mail-yw1-f198.google.com with SMTP id 00721157ae682-4528903f275so72645327b3.8 for ; Wed, 21 Dec 2022 06:56:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ovBRjIXwZ70tlY+skCpeXAvAlxiaqxk455V7X3zOcy0=; b=Ib8uxSLri6Rr4QzpIo0a2rE4kot1DfSB00HUnLaYWks81/fZICaQAPTZ2+9IAoN6GI wLQfrwu8/2BzCnByAOHEJHJFktZAPZ9rb6VW5aQvEtUYIkHxUopBWPvL1eZNGaAkwLe8 2Q416wj6JARyrX+EpOam40TwCcIDA9n7ONmkC4y62JC6wULjrIj6MsQC1wRYvG/ZwcQn /6Y0QHjbCsYvOcVmBXRBXUfqfCSUAXJWWAN+rBi6p1TrY1qDvDLAP+G6Psxncgp4EAII zlUZYx6UUxGKk1ZzAXumhrNfbyfPyILGmUK0pQ941cRGAkIQSeHVWjV0MXw2Op94rBAy PBcw== X-Gm-Message-State: AFqh2kp/En2gvzVVSuUYbj7wXWqbkRxX/2dQrzl0NpwqKYtgk2DNHb46 5zodBg2Hedm/sMJjLZtMIixtHUPyeMLhQE9SAjcYvZLHvX5yA7aULvdrn0dBc3Yrl4/OqIIfoUh vmeunpa1JStQ+kWd67w== X-Received: by 2002:a81:6c15:0:b0:427:adae:fef9 with SMTP id h21-20020a816c15000000b00427adaefef9mr1843972ywc.50.1671634577370; Wed, 21 Dec 2022 06:56:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXs5yQWFYJqGD3vfGMgXm2j244oFL4XCKKtUQSjki30egs/o/juInSpEupPCE5F4JWCW+DBDyw== X-Received: by 2002:a81:6c15:0:b0:427:adae:fef9 with SMTP id h21-20020a816c15000000b00427adaefef9mr1843954ywc.50.1671634577063; Wed, 21 Dec 2022 06:56:17 -0800 (PST) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id az39-20020a05620a172700b006fbbdc6c68fsm10878216qkb.68.2022.12.21.06.56.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 06:56:16 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Wed, 21 Dec 2022 09:56:15 -0500 (EST) To: Patrick Palka cc: gcc-patches@gcc.gnu.org, jason@redhat.com Subject: Re: [PATCH] c++: get_nsdmi in template context [PR108116] In-Reply-To: <20221221145254.389983-1-ppalka@redhat.com> Message-ID: <72179c67-7d4c-e098-b1d2-238ab854a925@idea> References: <20221221145254.389983-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII 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,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 Wed, 21 Dec 2022, 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? > > Bootstrapped and regtested on x86_64-pc-linux-gnu. Note this is a 12 regression so I suppose there's also the question of what's safest to backport vs what's the best fix.. > > 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{}; > +}; > -- > 2.39.0.95.g7c2ef319c5 > >