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]

Bug on Inheritance and Inner Class


Hello,

It seems there is a bug in the process of searching members in g++
compiler, at least in the version of 2.95.2 and the latest snapshot. 
I found the compiler is confused when each of an inner class and its
enclosing class has a different member of the same name
("same_name_member" in the following example). 
In my observation, the error occurs when the following conditions are
fulfilled:
 - the member of the inner class is defined in its parent class, and 
 - the parent class is given by a template parameter of the enclosing
   class. 

Here is a small example: 

struct InnerData // a parent class
{
  bool same_name_member;
};

template <class InnerRep=InnerData> // an enclosing class
class Outer
{
private:
  struct Inner : InnerRep // InnerData // it's ok if we directly use InnerData
  {
  private:
    // bool same_name_member; // it's ok if the member defined here
  public:
    Inner(bool s=true) { same_name_member = s; }
    bool read_value() const	{ return same_name_member; }
  };
public:
  int same_name_member()	{ return 0; }
  Outer()
    {
      bool value = Inner().read_value();
    }
};

int main()
{
  Outer<> o;
}


G++ 2.95.2 results in the following errors
% g++ inherited-inner-class-bug.cc

inherited-inner-class-bug.cc: In method `Outer<InnerData>::Inner::Inner(bool = true)':
inherited-inner-class-bug.cc:22:   instantiated from `Outer<InnerData>::Outer()'
inherited-inner-class-bug.cc:28:   instantiated from here
inherited-inner-class-bug.cc:15: invalid use of member (did you forget the `&' ?)
inherited-inner-class-bug.cc: In method `bool Outer<InnerData>::Inner::read_value() const':
inherited-inner-class-bug.cc:22:   instantiated from `Outer<InnerData>::Outer()'
inherited-inner-class-bug.cc:28:   instantiated from here
inherited-inner-class-bug.cc:16: invalid operands `{unknown type}' and `int' to binary `operator !='

Egcs-20000925 results in the following errors
%g++ inherited-inner-class-bug.cc

inherited-inner-class-bug.cc: In constructor `Outer<InnerRep>::Inner::Inner 
   (bool) [with InnerRep = InnerData]':
inherited-inner-class-bug.cc:22:   instantiated from `Outer<InnerRep>::Outer () [with InnerRep = InnerData]'
inherited-inner-class-bug.cc:28:   instantiated from here
inherited-inner-class-bug.cc:15: invalid use of member (did you forget the `&' 
   ?)
inherited-inner-class-bug.cc: In member function `bool 
   Outer<InnerRep>::Inner::read_value () const [with InnerRep = InnerData]':
inherited-inner-class-bug.cc:22:   instantiated from `Outer<InnerRep>::Outer () [with InnerRep = InnerData]'
inherited-inner-class-bug.cc:28:   instantiated from here
inherited-inner-class-bug.cc:16: cannot resolve overloaded function 
   `same_name_member' based on conversion to type `bool'

Thank you,
---
KANEKO Tomoyuki <kaneko@graco.c.u-tokyo.ac.jp>
// KAWAI Laboratory
// Graduate School of Arts and Sciences, The University of Tokyo

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