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.129.124]) by sourceware.org (Postfix) with ESMTPS id CE96F3858434 for ; Wed, 9 Mar 2022 18:09:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CE96F3858434 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-561-Emju1X_DO_CSd-tSaO3T6A-1; Wed, 09 Mar 2022 13:09:11 -0500 X-MC-Unique: Emju1X_DO_CSd-tSaO3T6A-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E9113501E1 for ; Wed, 9 Mar 2022 18:09:10 +0000 (UTC) Received: from pdp-11.hsd1.ma.comcast.net (unknown [10.22.10.0]) by smtp.corp.redhat.com (Postfix) with ESMTP id A122880FDB; Wed, 9 Mar 2022 18:09:05 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [PATCH] c++: ICE with operator delete [PR104846] Date: Wed, 9 Mar 2022 13:09:02 -0500 Message-Id: <20220309180902.976725-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-13.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_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Mar 2022 18:09:14 -0000 This is an ICE-on-invalid with "auto operator delete[] (void *)" whose return type must be void. The return type is checked in coerce_delete_type but we never got there in this test, because we took the wrong path in grokdeclarator, set type to error_mark_node, ended up creating a FIELD_DECL with build_decl, and confused grokmethod by giving it a FIELD_DECL. Fixed by not taking the data member path for a FUNCTION_TYPE. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? PR c++/104846 gcc/cp/ChangeLog: * decl.cc (grokdeclarator): Check FUNC_OR_METHOD_TYPE_P before giving data member errors. gcc/testsuite/ChangeLog: * g++.dg/init/delete5.C: New test. --- gcc/cp/decl.cc | 2 +- gcc/testsuite/g++.dg/init/delete5.C | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/init/delete5.C diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 992e38385c2..12f2524aafe 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -13751,7 +13751,7 @@ grokdeclarator (const cp_declarator *declarator, } else if (decl_context == FIELD) { - if (!staticp && !friendp && TREE_CODE (type) != METHOD_TYPE) + if (!staticp && !friendp && !FUNC_OR_METHOD_TYPE_P (type)) if (tree auto_node = type_uses_auto (type)) { location_t tloc = declspecs->locations[ds_type_spec]; diff --git a/gcc/testsuite/g++.dg/init/delete5.C b/gcc/testsuite/g++.dg/init/delete5.C new file mode 100644 index 00000000000..3555f43bbb0 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/delete5.C @@ -0,0 +1,8 @@ +// PR c++/104846 +// { dg-do compile { target c++14 } } + +struct S { + auto operator delete (void *) {} // { dg-error ".operator delete. must return type .void'" } + auto operator delete[] (void *) {} // { dg-error ".operator delete. must return type .void'" } +}; + base-commit: bded0d549fdfdc1328b2c0189dc5f8593b4cbe42 -- 2.35.1