From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10928 invoked by alias); 6 Oct 2010 21:20:13 -0000 Received: (qmail 10909 invoked by uid 22791); 6 Oct 2010 21:20:12 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 06 Oct 2010 21:20:08 +0000 From: "yuri at tsoft dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/45917] New: Friend of friend is allowed the access to the private type through the template X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: yuri at tsoft dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Wed, 06 Oct 2010 21:20:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-10/txt/msg00570.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45917 Summary: Friend of friend is allowed the access to the private type through the template Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: yuri@tsoft.com testcase below has struct R as private in class F. class F declares class Q a friend, allowing it to see it's private members. But operator<< is friend in Q, not in F. Why is it allowed for operator<< to instantiate list but not R r? This is a bug. --- testcase --- #include #include using namespace std; class F { private: struct R { }; // R friend class Q; class Q { list l; friend ostream& operator<<(ostream &os, const Q &q) { // R r; // this breaks! for (list::const_iterator it = q.l.begin(); it != q.l.end(); it++) { // this doesn't break! Why? } return os; } }; // Q }; // F