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 DD4443858C2B for ; Thu, 20 Jul 2023 14:29:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DD4443858C2B 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=1689863364; 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=raZy4rsE5SiaSdPAahUu7YwKj6VI+nslxIRDDwvdsbQ=; b=gqNtpAdsorsYmTeE1QTu+TKJQfVh03En19LseUo8jAmtefJcy6TAgRAQDipBfQE4cecwGH ttBoTUR/0/4GS4y1FvHv36eB553dKg5xWPyZ5SncTKc8c0vEk8a6mUq/se7qE2ziI0pDlK 2vaDHi+z3uNPqLDYxOzoDvhQjw9iio8= 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_256_GCM_SHA384) id us-mta-510-kHKGWU_zOS-AwR8uoFnnBA-1; Thu, 20 Jul 2023 10:29:22 -0400 X-MC-Unique: kHKGWU_zOS-AwR8uoFnnBA-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-7659b44990eso110677285a.1 for ; Thu, 20 Jul 2023 07:29:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689863362; x=1690468162; 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=raZy4rsE5SiaSdPAahUu7YwKj6VI+nslxIRDDwvdsbQ=; b=LwsWFzLmcBYhdSb5FOhn5Xel6D9IcxboBueBjTfGZyNTw78a09lHaBhp73vx/9J5RN moUXEq5M3NpHV2nGWbWnBGyhXGkZ44w1B83C2+BKsfTGD64XDADnpyCJqquF4l6mzypx iBq2OFcqcoXiTAUmJ26p33m0Fm5lT1/j6foGy6fxwrlpFkz6dmuomuzddVabw1/vuVmY vN5pJ9Gk/VeV63FqarON4BTBnKPO4nFAn9t0424tpEWSW8C/SMxbdxgZeTAYj6IYNypV iTyXQi5SvvLfkM/6mAQ9uumMA6QURMikJbAbM6mj0OrBWJ3AuX2lbkevV1uKMAF/pcDC kpAw== X-Gm-Message-State: ABy/qLboS3pWEq2bLn9Weamkxv/ZXip71rR+B4/gktrUCwdSqwEYDIah MIdFA1/rremnikzrZ69D7NmopGCuQJ69ajjASC1HHivovQLFuTwR1/i4K96F2gnhixvbsWunwH3 Z9FZodTI+1H3SACBn3g== X-Received: by 2002:a05:620a:2d83:b0:763:e0ba:5e95 with SMTP id tr3-20020a05620a2d8300b00763e0ba5e95mr5145014qkn.72.1689863362330; Thu, 20 Jul 2023 07:29:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlF9LZ35daLE4cZ4hOfpJMgc7f8vGKc7nJNHBKmzdwIS1slj0KecLAc+jOk7h3eZ2Bwr2KA7IQ== X-Received: by 2002:a05:620a:2d83:b0:763:e0ba:5e95 with SMTP id tr3-20020a05620a2d8300b00763e0ba5e95mr5144999qkn.72.1689863361992; Thu, 20 Jul 2023 07:29:21 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id s17-20020a05620a031100b00767f5c70b3dsm290863qkm.96.2023.07.20.07.29.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Jul 2023 07:29:21 -0700 (PDT) Message-ID: Date: Thu, 20 Jul 2023 10:29:20 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v2] c++: fix ICE with designated initializer [PR110114] To: Marek Polacek Cc: Patrick Palka , GCC Patches References: <20230719180053.46101-1-polacek@redhat.com> <3efd2e0c-1c18-de91-4708-dfd1892ecb11@idea> 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.6 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_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 7/20/23 10:08, Marek Polacek wrote: > On Wed, Jul 19, 2023 at 03:24:10PM -0400, Jason Merrill wrote: >> On 7/19/23 14:38, Marek Polacek wrote: >>> 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. >> >> Maybe return NULL for the incomplete case here, rather than just skipping >> reshape_init? >> >> /* Call reshape_init early to remove redundant braces. */ >> if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr) >> && CLASS_TYPE_P (to) >> && COMPLETE_TYPE_P (complete_type (to)) >> && !CLASSTYPE_NON_AGGREGATE (to)) >> { >> expr = reshape_init (to, expr, complain); >> if (expr == error_mark_node) >> return NULL; >> from = TREE_TYPE (expr); >> } >> >> If that doesn't work, the patch is fine as-is. > > It does work, with one test tweak (which I don't think is a regression): > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? OK. > -- >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 implicit_conversion_1; we'd > return NULL anyway due to: > > if (i < CONSTRUCTOR_NELTS (ctor)) > return NULL; > > in build_aggr_conv. > > PR c++/110114 > > gcc/cp/ChangeLog: > > * call.cc (implicit_conversion_1): Return early if the type isn't > complete. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp0x/initlist100.C: Adjust expected diagnostic. > * g++.dg/cpp2a/desig28.C: New test. > * g++.dg/cpp2a/desig29.C: New test. > --- > gcc/cp/call.cc | 19 +++++++++++-------- > gcc/testsuite/g++.dg/cpp0x/initlist100.C | 4 ++-- > gcc/testsuite/g++.dg/cpp2a/desig28.C | 17 +++++++++++++++++ > gcc/testsuite/g++.dg/cpp2a/desig29.C | 10 ++++++++++ > 4 files changed, 40 insertions(+), 10 deletions(-) > 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..673ec91d60e 100644 > --- a/gcc/cp/call.cc > +++ b/gcc/cp/call.cc > @@ -2059,15 +2059,18 @@ implicit_conversion_1 (tree to, tree from, tree expr, bool c_cast_p, > complain &= ~tf_error; > > /* Call reshape_init early to remove redundant braces. */ > - if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr) > - && CLASS_TYPE_P (to) > - && COMPLETE_TYPE_P (complete_type (to)) > - && !CLASSTYPE_NON_AGGREGATE (to)) > + if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr) && CLASS_TYPE_P (to)) > { > - expr = reshape_init (to, expr, complain); > - if (expr == error_mark_node) > - return NULL; > - from = TREE_TYPE (expr); > + to = complete_type (to); > + if (!COMPLETE_TYPE_P (to)) > + return nullptr; > + if (!CLASSTYPE_NON_AGGREGATE (to)) > + { > + expr = reshape_init (to, expr, complain); > + if (expr == error_mark_node) > + return nullptr; > + from = TREE_TYPE (expr); > + } > } > > if (TYPE_REF_P (to)) > diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist100.C b/gcc/testsuite/g++.dg/cpp0x/initlist100.C > index 9d80a004c17..6865d34a6f9 100644 > --- a/gcc/testsuite/g++.dg/cpp0x/initlist100.C > +++ b/gcc/testsuite/g++.dg/cpp0x/initlist100.C > @@ -2,9 +2,9 @@ > // { dg-do compile { target c++11 } } > > namespace std { > -template class initializer_list; // { dg-message "declaration" } > +template class initializer_list; > } > > template struct B { B (std::initializer_list); }; > struct C { virtual int foo (); }; > -struct D : C {} d { B { D {} } }; // { dg-error "incomplete|no matching" } > +struct D : C {} d { B { D {} } }; // { dg-error "no matching" } > 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: b86c0fe327a5196a316bd698d12765b08de5dce7