From patchwork Thu Sep 3 06:10:27 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lunex X-Patchwork-Id: 2297274 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=T9ceSAki; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=38.145.34.32; helo=vm01.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hb8Nq2Vzqz1xvg for ; Thu, 03 Sep 2026 16:11:07 +1000 (AEST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 61B834BA79B8 for ; Thu, 3 Sep 2026 06:11:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61B834BA79B8 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=T9ceSAki X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 2259E4BA79A0 for ; Thu, 3 Sep 2026 06:10:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2259E4BA79A0 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2259E4BA79A0 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788415836; cv=none; b=He1LsbsVcpw5j39ARjq3AIqynBOjByj2OmB9hT9yXJcYQpwPGxU6DQZpwDVQ2Vtw7cXA9aj8jFbunU3x7OmPSl8pj014gDp948G2EVAd8jOBZcgNcjJOOOSFNMOpx0bNe3pXLw5YBrHXwLcaZr/mtxf24o6mr45adRqBglIl8bU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788415836; c=relaxed/simple; bh=UptEMvj15NBHcIOKjh/e2DSduNrEOipVzZpn5dce/fI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=eEd63mCc/r2ZjVeP/yz1t1GqrHMqD6tHwgyfuNpzwPJJs7ueANceDbhM7aI8jDaR4mizI4pXUUkTT36s+mBZCr6c8fZofuRdAe2BRroZm3m8sCkSwVtc/nlkl6yNo80q9RDqW+0gJ1m8Q4MbMmIYmjOU57XeewpeEvxJjEuNJDs= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=T9ceSAki DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2259E4BA79A0 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-2d9db539a54so17908635ad.0 for ; Wed, 02 Sep 2026 23:10:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788415835; x=1789020635; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=eyfT49tXA+vIADITTDjY02QabYA1kZoFl+I4vY+aTYM=; b=T9ceSAkiSyiPQ3kYM76ipfxbHOkc7noH5QI8GBTZ3Z7JskFDRnnQsVhjcZL9mduLaS Hqm2tMep5Ocff6Y6dLqq4GESFDL2D9jIBC8STuAxJktcmNqd4JUjkOlsuo269QBUR7+1 yOWBUy5J8VWLw1NtwO/jsmaH+BhBwz57HKIqq281b+5pxNrOpwzwd61wjo/VRTV4xih6 1TNGy14QUfcQq8T+KcCH2Hv5BM+OGSClNJNpKZESGNwr1k7E4o8nJWUTYAWK11cC6zfm PrCbztpTikbz7auj+VPbM8/ieW1t8Gh3e3KW4Mrhp93YUSf6GsYBADyRAOldNgmgpk+W zwfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788415835; x=1789020635; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=eyfT49tXA+vIADITTDjY02QabYA1kZoFl+I4vY+aTYM=; b=AAlYQl9B62ww6A5LPAkh2XA2fGBJ9Ze0hjIMdolelJ/ZgOZfIrXbvr9PkuFj9xR3C/ M+FCx2jsawcAB6GpNlD5C5E8hJyO2k8P/XhmP1kkyk5m4fYq6IR0S7qcE+cH38reYNq8 vlhX6hBghATraGNnajHhAQwwAYV16ZT0XBEu98hhtK6ztgrrDHo4sXbMMzHntvIOwwrn 9SKp8QA9ENCjwxsfK0GnylNwzOa/FaIIGobjVdI2GLIh1D9PMcs8M85OlLcfD/2GZFAJ WcYZQmzCViHKr3FiYfY46n/BBs1iaDiLLeeo3KpXHrnuj41aeMB+BPLMgvAM1d9x5BKn aBnw== X-Gm-Message-State: AFuF++nGSky72YMmdPubQxasOB+TsKMNFbn2YHOM0ch0pQcSOrdx1HFB yEP3sqSdcdLPCCeACi+rxtSdhEFYcJpp8i3plyeEJDzzqytTIDZ/DJTQB4oevCiR X-Gm-Gg: AYBFou27/KolKo9DVcc9HJi2zXm/4ZNQomFIRoGFWTBWDOm4q2HgQY3c0JAEY1wrv9R fpSdFU6yQfhkG66VR/DBuFw0zUENm+huZMHN7D9rO2TR62bwuZM+iqTBrc/skswZ4C780OTWbv8 +WJBuJoFAPImk/5A4WTMxYjZwSkL6PTi+xRq/V1iHPcPiuQtKVZSyuwSSmhyz9lwlqGS4zkVopU 3tV1dp/J1HBRh3ToOPcEm2m9VU7wcy4gJQmVkod5teQqa+zFofSr4uxuUy640+KqbX6xn5MXNY6 v5Pp78R406BUf+PJZC5ToCEEJCw7+R9AH7wSBP5twFYNaTWpTayT9FI4mnJLSPR+hejhqkkm/wm RjQUcMlar1x09wrgOUT3Weqd82YftdVfyf5iCofwEBXeKOlOLavOyzI0pm5CGDFcNjYG8QZcpqm ZfqRzCSFqITd4rHyNcfGZ9Jvvr/NlCaq7phUj3eMgZEhBCCCn96eMXomM= X-Received: by 2002:a17:902:ffd0:b0:2d6:e401:9676 with SMTP id d9443c01a7336-2daec5f5feamr134546275ad.1.1788415834910; Wed, 02 Sep 2026 23:10:34 -0700 (PDT) Received: from nixos ([103.176.18.217]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2dafed6ec65sm4627645ad.77.2026.09.02.23.10.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2026 23:10:34 -0700 (PDT) From: imlunex2011@gmail.com To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, ppalka@gcc.gnu.org, Lunex Subject: [PATCH] c++: fix ICE on friend with explicit object parameter [PR-122258] Date: Thu, 3 Sep 2026 12:10:27 +0600 Message-ID: <20260903061027.50275-1-imlunex2011@gmail.com> X-Mailer: git-send-email 2.54.0 MIME-Version: 1.0 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~incoming=patchwork.ozlabs.org@gcc.gnu.org From: Lunex Hope you are well, So this is patch and here is what it is about - A 'friend' is not a member but 'this Self &&' only works for members. GCC missed this check, so it marked the friend as a member and later crashed with no access info to check. Now we reject friend functions that use an explicit object parameter, gcc/cp/ChangeLog: PR c++/122258 * decl.cc (grokdeclarator): Diagnose friend with explicit object parameter. gcc/testsuite/ChangeLog: PR c++/122258 * g++.dg/cpp23/explicit-obj-diagnostics13.C: New test. --- gcc/cp/decl.cc | 7 ++++ .../g++.dg/cpp23/explicit-obj-diagnostics13.C | 37 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics13.C diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 55badc9ee..246642aea 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -15673,6 +15673,13 @@ grokdeclarator (const cp_declarator *declarator, error_at (DECL_SOURCE_LOCATION (xobj_parm), "a non-member function cannot have " "an explicit object parameter"); + else if (friendp) + { + error_at (DECL_SOURCE_LOCATION (xobj_parm), + "a friend function cannot have " + "an explicit object parameter"); + is_xobj_member_function = false; + } else { if (virtualp) diff --git a/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics13.C b/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics13.C new file mode 100644 index 000000000..1434ad252 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics13.C @@ -0,0 +1,37 @@ +// P0847R7 +// { dg-do compile { target c++23 } } + +#include + +// PR c++/122258 - friend with explicit object param must be rejected + +struct type { + template + friend auto get(this Self &&self) { return 0; } // { dg-error "a friend function cannot have an explicit object parameter" } +}; + +struct S { + friend void f(this S &); // { dg-error "a friend function cannot have an explicit object parameter" } + friend void g(this S &&); // { dg-error "a friend function cannot have an explicit object parameter" } +}; + +struct U { + template + friend void h(this Self &&); // { dg-error "a friend function cannot have an explicit object parameter" } + template + friend void k(this Self &&) {} // { dg-error "a friend function cannot have an explicit object parameter" } +}; + +struct V { + friend void m(this V &) {} // { dg-error "a friend function cannot have an explicit object parameter" } +}; + +namespace std { +template<> struct tuple_size : integral_constant {}; +template struct tuple_element { using type = int; }; +} + +void test_sb() +{ + auto [a] = type(); +}