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 333853858436 for ; Wed, 19 Jul 2023 18:38:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 333853858436 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=1689791914; 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=jytDtvAij6mHQsNF1Ndb1fL9+TezMTRuWJo3z7Dy9xs=; b=ar/19pROdRZJL4H+d6oLmtKecyXBjcRYOfDQIrLU0x2Rq7fkg0f6TFSKqjcdEbxFoqom/q T3BCrzVzHdIzTgpWnAQAJGa88Dd1NCrUwYVqTh2ZH6D141SvIdNcqts+KO5K5qE/s8sHiV Jfh5gOHF00w3RjL3Jneftiac8hisnwE= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-516-LYPxJuACM8y_hecl8CIefw-1; Wed, 19 Jul 2023 14:38:33 -0400 X-MC-Unique: LYPxJuACM8y_hecl8CIefw-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7659b44990eso667929785a.1 for ; Wed, 19 Jul 2023 11:38:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689791912; x=1692383912; 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=jytDtvAij6mHQsNF1Ndb1fL9+TezMTRuWJo3z7Dy9xs=; b=KqXe1roQjgozHZbflJjXRAKiARJL4PXGsgA/qlJG+YNZaRvZctoN0DQ1tuvNu4DTP2 /Gdee96zI0C8ldJ66PxxfX5SV1fs88oHjmuPo0j4SCF0zrb1a8++dJCrmOihcCnxxuGN izCVkWjclgBJdbvs1OLsNF7JsuFMxZdsF3WuObDRe0XUMMh912xF/TaeAQJucc0wYJlQ 710qd1x9P+TQVY/cu2wEw5wYMss4XHUM10puTZznC89jnoFJNjLE357k2LYeOSjAJpnU 9PRV2hvLnuOy8FOEfM/kAwaMHxfjc7R8uhY1qbz33FMEsWmAxvUDJxKMgRQduQmsVrIS MCNA== X-Gm-Message-State: ABy/qLZ6cvqGuOOw6Zu/TfTD6bq6DWiDIsk7icZELhVyD8yDP/OeTnkI ERmV+6rG23EhQo4/QVsfzMie6Qohk2B6jYw16Ac3SjVTHyAc0ZYK7BekLKVmS1T447mu9WvC0sY zC6Mw1P6fcqM0782/nw== X-Received: by 2002:a0c:f38e:0:b0:62b:3c25:5ae9 with SMTP id i14-20020a0cf38e000000b0062b3c255ae9mr2651640qvk.65.1689791912398; Wed, 19 Jul 2023 11:38:32 -0700 (PDT) X-Google-Smtp-Source: APBJJlGwAkA7SLEJeQ3oebzwkQvuMTdUL60MfY8WaUsTW4URISB+bh5eFhKoxMEzdWnKpqbeeBHNgw== X-Received: by 2002:a0c:f38e:0:b0:62b:3c25:5ae9 with SMTP id i14-20020a0cf38e000000b0062b3c255ae9mr2651630qvk.65.1689791912163; Wed, 19 Jul 2023 11:38:32 -0700 (PDT) Received: from redhat.com (2603-7000-9500-34a5-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:34a5::1db4]) by smtp.gmail.com with ESMTPSA id p6-20020a0cf546000000b0062635bd22aesm1619483qvm.109.2023.07.19.11.38.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 11:38:31 -0700 (PDT) Date: Wed, 19 Jul 2023 14:38:29 -0400 From: Marek Polacek To: Patrick Palka Cc: GCC Patches , Jason Merrill Subject: Re: [PATCH] c++: fix ICE with designated initializer [PR110114] Message-ID: References: <20230719180053.46101-1-polacek@redhat.com> <3efd2e0c-1c18-de91-4708-dfd1892ecb11@idea> MIME-Version: 1.0 In-Reply-To: <3efd2e0c-1c18-de91-4708-dfd1892ecb11@idea> User-Agent: Mutt/2.2.9 (2022-11-12) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-12.5 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_H4,RCVD_IN_MSPIKE_WL,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 List-Id: On Wed, Jul 19, 2023 at 02:32:15PM -0400, Patrick Palka wrote: > On Wed, 19 Jul 2023, Marek Polacek wrote: > > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > LGTM. It might be preferable to check COMPLETE_TYPE_P in the caller > instead, so that we avoid inspecting CLASSTYPE_NON_AGGREGATE on an > incomplete class type, and so that the caller doesn't "commit" to > building an aggregate conversion. Perhaps. I wanted to avoid the call to build_user_type_conversion_1. I could add an early return to implicit_conversion_1 but I'd have to move some code around not to check COMPLETE_TYPE_P before complete_type. > > > > -- >8 -- > > > > r13-1227 added an assert checking that the index in a CONSTRUCTOR > > is a FIELD_DECL. That's a reasonable assumption but in this case > > we never called reshape_init due to the type being incomplete, and > > so the index remained an identifier node: get_class_binding never > > got around to looking up the FIELD_DECL. > > > > We can avoid the crash by returning early in build_aggr_conv; we'd > > return NULL anyway due to: > > > > if (i < CONSTRUCTOR_NELTS (ctor)) > > return NULL; > > > > PR c++/110114 > > > > gcc/cp/ChangeLog: > > > > * call.cc (build_aggr_conv): Return early if the type isn't > > complete. > > > > gcc/testsuite/ChangeLog: > > > > * g++.dg/cpp2a/desig28.C: New test. > > * g++.dg/cpp2a/desig29.C: New test. > > --- > > gcc/cp/call.cc | 5 +++++ > > gcc/testsuite/g++.dg/cpp2a/desig28.C | 17 +++++++++++++++++ > > gcc/testsuite/g++.dg/cpp2a/desig29.C | 10 ++++++++++ > > 3 files changed, 32 insertions(+) > > create mode 100644 gcc/testsuite/g++.dg/cpp2a/desig28.C > > create mode 100644 gcc/testsuite/g++.dg/cpp2a/desig29.C > > > > diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc > > index b55230d98aa..0af20a81717 100644 > > --- a/gcc/cp/call.cc > > +++ b/gcc/cp/call.cc > > @@ -986,6 +986,11 @@ build_aggr_conv (tree type, tree ctor, int flags, tsubst_flags_t complain) > > tree empty_ctor = NULL_TREE; > > hash_set pset; > > > > + /* We've called complete_type on TYPE before calling this function, but > > + perhaps it wasn't successful. */ > > + if (!COMPLETE_TYPE_P (type)) > > + return nullptr; > > + > > /* We already called reshape_init in implicit_conversion, but it might not > > have done anything in the case of parenthesized aggr init. */ > > > > diff --git a/gcc/testsuite/g++.dg/cpp2a/desig28.C b/gcc/testsuite/g++.dg/cpp2a/desig28.C > > new file mode 100644 > > index 00000000000..b63265fea51 > > --- /dev/null > > +++ b/gcc/testsuite/g++.dg/cpp2a/desig28.C > > @@ -0,0 +1,17 @@ > > +// PR c++/110114 > > +// { dg-do compile { target c++20 } } > > + > > +struct A { > > + int a,b; > > +}; > > + > > +struct B; > > + > > +void foo(const A &) {} > > +void foo(const B &) {} > > + > > +int > > +main () > > +{ > > + foo({.a=0}); > > +} > > diff --git a/gcc/testsuite/g++.dg/cpp2a/desig29.C b/gcc/testsuite/g++.dg/cpp2a/desig29.C > > new file mode 100644 > > index 00000000000..bd1a82b041d > > --- /dev/null > > +++ b/gcc/testsuite/g++.dg/cpp2a/desig29.C > > @@ -0,0 +1,10 @@ > > +// PR c++/110114 > > +// { dg-do compile { target c++20 } } > > + > > +struct B; > > + > > +void foo(const B &) {} > > + > > +int main() { > > + foo({.a=0}); // { dg-error "invalid" } > > +} > > > > base-commit: 2971ff7b1d564ac04b537d907c70e6093af70832 > > -- > > 2.41.0 > > > > > Marek