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: unassig...@gcc.gnu.org
        ReportedBy: y...@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 via email to