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]

access denied to a protected member of a virtual base class



  egcs-2.90.16 971105 (gcc2-970802 experimental)

 I dont know if it is a bug. A protected method of a virtual base
class cannot be call in the derived base class if the base class is
not a direct parent.

vb.cc: In method `void dd1::f()':
vb.cc:4: `void base::f()' is protected
vb.cc:25: within this context
vb.cc: In method `void d1_and_base::f()':
vb.cc:4: `void base::f()' is protected
vb.cc:36: within this context

 In procedure build_member_call ( cp/init.c:1681 ), a call to
get_base_distance initializes the variable basetype_path, but later,
a call to convert_force, which also calls get_base_distance, modifies
the chain basetype_path is pointing to. Adding a call to
get_base_distance after convert_force fix this problem.

Thanks

Pierre TURLAIS.

------------------- Modif in cp/init.c -----------------------
*** cp/init.c~  Fri Nov  7 13:20:39 1997
--- cp/init.c   Fri Nov  7 16:15:03 1997
***************
*** 1731,1737 ****
    /* No object?  Then just fake one up, and let build_method_call
       figure out what to do.  */
    if (current_class_type == 0
!       || get_base_distance (type, current_class_type, 0, &basetype_path) == -1)
      dont_use_this = 1;
  
    if (dont_use_this)
--- 1731,1737 ----
    /* No object?  Then just fake one up, and let build_method_call
       figure out what to do.  */
    if (current_class_type == 0
!       || get_base_distance (type, current_class_type, 0, 0) == -1)
      dont_use_this = 1;
  
    if (dont_use_this)
***************
*** 1753,1758 ****
--- 1753,1759 ----
          tree newtype = build_type_variant (type, TYPE_READONLY (oldtype),
                                             TYPE_VOLATILE (oldtype));
          decl = convert_force (build_pointer_type (newtype), olddecl, 0);
+         get_base_distance (type, current_class_type, 0, &basetype_path);
        }
        else
        decl = olddecl;

------------------------------   vb.c   ----------------------------

class base {
protected:
    virtual void f();
};

class d1 : public virtual base {
protected:
    void f();
};

void d1::f()
{
    base::f();
}

class dd1 : public virtual d1 {
protected:
     void f();
};

void dd1::f()
{
    d1::f();
    base::f();
}

class d1_and_base : public virtual d1, public virtual base {
protected:
     void f();
};

void d1_and_base::f()
{
    d1::f();
    base::f();
}


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