public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "yuri at tsoft dot com" <gcc-bugzilla@gcc.gnu.org>
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
Date: Wed, 06 Oct 2010 21:20:00 -0000	[thread overview]
Message-ID: <bug-45917-4@http.gcc.gnu.org/bugzilla/> (raw)

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<R> but not R r? This is a
bug.

--- testcase ---
#include <list>
#include <ostream>
using namespace std;

class F {
private:
  struct R {
  }; // R
  friend class Q;
  class Q {
    list<R> l;
    friend ostream& operator<<(ostream &os, const Q &q) {
      // R r; // this breaks!
      for (list<R>::const_iterator it = q.l.begin(); it != q.l.end(); it++) {
// this doesn't break! Why?
      }
      return os;
    }
  }; // Q
}; // F


             reply	other threads:[~2010-10-06 21:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-06 21:20 yuri at tsoft dot com [this message]
2010-10-06 21:40 ` [Bug c++/45917] " redi at gcc dot gnu.org
2010-10-06 21:48 ` [Bug c++/45917] inaccessible types allowed as template argument in nested-name-specifier redi at gcc dot gnu.org
2013-03-14 21:15 ` jason at gcc dot gnu.org
2013-03-14 21:40 ` jason at gcc dot gnu.org
2013-03-17  2:40 ` jason at gcc dot gnu.org
2013-03-22 11:18 ` paolo.carlini at oracle dot com
2013-04-01 21:04 ` jason at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-45917-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).