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 CD3D53858C33 for ; Wed, 19 Jul 2023 18:01:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD3D53858C33 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=1689789661; 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; bh=j7/UIsKbAUDv9delZzg6EuxfhrZgsyrAp6T72plAQu0=; b=PZHQtS5KXlqigQkcAtZnjtNsDVoQiTXRoV+mpgcIcFwQNjSiAgjFPFcH5ycyVSDzWcted8 a9Ol9sAPOVm7eG3+FA8O6qkqUDKwjFGI16NVagJxhOaogS/UV8Pw1y4pbkCyxgXWVgBSJE TY/lVRc4EAK8eQqSWEPpPsenJocF4z4= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-190-6LDKwL2QNGKgWtHIRaKP6g-1; Wed, 19 Jul 2023 14:01:00 -0400 X-MC-Unique: 6LDKwL2QNGKgWtHIRaKP6g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9724929AB3EB for ; Wed, 19 Jul 2023 18:00:59 +0000 (UTC) Received: from pdp-11.lan (unknown [10.22.9.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5AD08C2C85C; Wed, 19 Jul 2023 18:00:59 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill Cc: Patrick Palka Subject: [PATCH] c++: fix ICE with designated initializer [PR110114] Date: Wed, 19 Jul 2023 14:00:53 -0400 Message-ID: <20230719180053.46101-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.3 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: Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >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