From patchwork Thu Jan 18 01:17:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 84311 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 80F23385842E for ; Thu, 18 Jan 2024 01:17:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 EAB413858CDB for ; Thu, 18 Jan 2024 01:17:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EAB413858CDB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EAB413858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705540642; cv=none; b=wSVkAWK+/wNlzDdXw6ajuopUmOAswrJxCoT45/f4eYm8bVkI6hyjyeA3ZBohjCtiTx29DDK6/yjxW+ZFXNl6U7x7XyvAMlGkPnuR9iKofjX4MWsy8ytWB6KgcZMqSPb8YkOPVy1NfTQ2pXxk6CvYtwEwDUX9mwLAjz29lT7RmNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705540642; c=relaxed/simple; bh=t3paG8zpgg1uRvPh3j0h5CNOgKPBezQEWWpCLJjVjYA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=GtyAdRiGOWnMctDwbuWp9x5D84HsUHj5nlWM4Kv1ROfEqzNmRzm7BLUVGloUdCNG+7VNe2iSAsGoImEZ1BiWj1QuckMZ1uvYxWaHWwukowzXq1ZBmlJOGiZi+rMhIt3jeh6EtxbNe7DWKRtRWTtMfkQDWWEQppNNcUgnM/N1I+4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705540640; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=l60hUZ/BQLGJ2AC6WQQ9uWxE9ECpK/5Yxhqqp6jx6yM=; b=gZxOk3Ds0urdTEpaFDflrsgndDCSF166Jt2SIFK7TLOfRHFIZ9Q86ZJIOvYyrX4Z28D29t dQvRDF+wwqj35v1/9WI9iEDozfg0z+GVU5qE7pd9dLHTtTu+8LDG7uDzecyflyywFxQUNQ 1GR0Vjtna0PposYi5jPvBYksZN9RHjc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-136-B5BIMipFNWisyzoMnRrilg-1; Wed, 17 Jan 2024 20:17:19 -0500 X-MC-Unique: B5BIMipFNWisyzoMnRrilg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E3A86833A06 for ; Thu, 18 Jan 2024 01:17:18 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.9.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF5E83C25; Thu, 18 Jan 2024 01:17:18 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [PATCH] c++: ICE when xobj is not the first parm [PR113389] Date: Wed, 17 Jan 2024 20:17:14 -0500 Message-ID: <20240118011714.451164-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.0 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_H3, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- In grokdeclarator/cdk_function the comment says that the find_xobj_parm lambda clears TREE_PURPOSE so that we can correctly detect an xobj that is not the first parameter. That's all good, but we should also clear the TREE_PURPOSE once we've given the error, otherwise we crash later in check_default_argument because the 'this' TREE_PURPOSE lacks a type. PR c++/113389 gcc/cp/ChangeLog: * decl.cc (grokdeclarator) : Set TREE_PURPOSE to NULL_TREE when emitting an error. gcc/testsuite/ChangeLog: * g++.dg/cpp23/explicit-obj-diagnostics10.C: New test. --- gcc/cp/decl.cc | 1 + gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics10.C | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics10.C base-commit: 4a8430c8c3abb1c2c14274105b3a621100f251a2 diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 322e48dee2e..3e41fd4fa31 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -13391,6 +13391,7 @@ grokdeclarator (const cp_declarator *declarator, if (TREE_PURPOSE (parm) != this_identifier) continue; bad_xobj_parm_encountered = true; + TREE_PURPOSE (parm) = NULL_TREE; gcc_rich_location bad_xobj_parm (DECL_SOURCE_LOCATION (TREE_VALUE (parm))); error_at (&bad_xobj_parm, diff --git a/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics10.C b/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics10.C new file mode 100644 index 00000000000..354823db166 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics10.C @@ -0,0 +1,8 @@ +// PR c++/113389 +// { dg-do compile { target c++23 } } + +struct A { + void foo(A, this A); // { dg-error "only the first parameter" } + void qux(A, this A, // { dg-error "only the first parameter" } + this A); // { dg-error "only the first parameter" } +};