http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57614

            Bug ID: 57614
           Summary: Friend declaration and qualified class member access
           Product: gcc
           Version: 4.7.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: roger.ferrer at bsc dot es

In the snippet below, a weird interaction happens between two overloaded friend
declarations and a class member access using a qualified id-expression. 

// -- test.cc
class  A
{
    protected:
        int s;
    public:
        A();
};

class  B : public A
{
    protected:
    public:
        B();

    // By reversing the order of these two declarations
    // you can change the location of the error
    friend void foo(B &, int);
    friend void foo(B &, B& b);
};

void foo(B& a, int)
{
    // This is only fine if this function was the first "friend" declared
    a.A::s = 3;
    // Always fine
    a.s = 3;
}

void foo(B& a, B& b)
{
    // This is only fine if this function was the first "friend" declared
    a.A::s = 3;
    // Always fine
    a.s = 3;
}
// -- end of test.cc

g++ is 4.7.3

$ g++ -c test.cc
test.cc: In function ‘void foo(B&, B&)’:
test.cc:4:7: error: ‘int A::s’ is protected
test.cc:32:7: error: within this context

If we reverse the order of the friend declarations we can change the error
location.

$ g++ -c test.cc
test.cc: In function ‘void foo(B&, int)’:
test.cc:4:7: error: ‘int A::s’ is protected
test.cc:24:7: error: within this context

The error seems to happen with the second overloaded friend declaration.

This problem can be worked around if the id-expression of the class member
access is unqualified.

Reply via email to