From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D69A638582A5; Fri, 26 Aug 2022 15:34:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D69A638582A5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661528046; bh=uGaoB50BskRxHgAvr8ornpVQOPmv3aoH+mbE0o/Q6MA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Z4XYx+DiGNL+clUXUunLVG2Ol4njCvj8PCH2urFZtwu7vL6EqCUPlIM42QpD/uz81 ad69dO9E1GL17VKQpU/41dl1tOFkHdGPRZQqLYz7uJ+8xYPULGcq4MqPE0fgDZT1vB IBItoMwZO/Df7b6hIaRsuwWHQ0sygs3TFALvUGR8= From: "herring at lanl dot gov" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106756] Overbroad friendship for nested classes Date: Fri, 26 Aug 2022 15:34:06 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: accepts-invalid X-Bugzilla-Severity: normal X-Bugzilla-Who: herring at lanl dot gov X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106756 --- Comment #2 from S. Davis Herring --- (In reply to Jonathan Wakely from comment #1) > "Declaring a class to be a friend implies that private and protected = members > of the class granting friendship can be named in the base-specifiers = and > member declarations of the befriended class." >=20=20=20=20=20 > A hidden friend is a syntactic member-declaration, but is it a "member > declaration"? That argument doesn't quite apply here: B is the class granting friendship,= but it's A's member being accessed. To allow this, we'd have to say that B's friendship gives f access to everything to which B has access, but that wou= ld just be transitive friendship, which is known to be wrong. That said, one can make a similar argument along the lines of "B is a member-declaration of A, and so f is part of a member-declaration itself", which puts us back on the old question of whether it matters whether the fr= iend is defined inside the class. Indeed, GCC still rejects the example modifie= d to use int f(A::B*) {return A::i;} but that's an even stronger contradiction with [class.nest]/4 (which uses "defined within a nested class").=