This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/38078] New: Friend Functions of the Base accessing Derived Class Members


struct aderived;
struct aderived2;

struct abase{
        abase() : pblc(0), prtd(0), prvt(0){}
public:
        int pblc;
protected:
        int prtd;
private:
        int prvt;

        friend void frb(abase *pb, aderived *pd);
};

struct aderived : protected abase{
        void fn(abase *pb, aderived* pd, aderived2 *pd2);
        friend void frd(abase *pb, aderived *pd, aderived2 *pd2);
};

struct aderived2 : aderived{};

void frb(abase *pb, aderived *pd){
        pb->pblc++;
        pb->prtd++;
        pb->prvt++;

        pd->pblc++;
        pd->prtd++;
        pd->prvt++;
}

int main(){}

This code gives the following compilation error:

j.cpp: In function void frb(abase*, aderived*):
j.cpp:16: error: int abase::prvt is private
j.cpp:35: error: within this context

However Visual Studio 2008 and Comeau Online Compiler give error in all the
three statements

a) pd->pblc++;
b) pd->prtd++;
c) pd->prvt++;


"ComeauTest.c", line 28: error: member "abase::pblc" (declared at line 7) is
          inaccessible
        pd->pblc++;
            ^

"ComeauTest.c", line 29: error: member "abase::prtd" (declared at line 9) is
          inaccessible
        pd->prtd++;
            ^

"ComeauTest.c", line 30: error: member "abase::prvt" (declared at line 11) is
          inaccessible
        pd->prvt++;


-- 
           Summary: Friend Functions of the Base accessing Derived Class
                    Members
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: blocker
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: anubhav dot saxena at wipro dot com
 GCC build triplet: i386-redhat-linux
  GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]