C++ Bug - Inline Member Function Hides Virtual Member Function

Josh Stern jstern@citilink.com
Sat Jun 5 05:54:00 GMT 1999


//compile this with g++ -c -DMAKEBUG tstcase.cc to observe the
// problem;  correct code fails to compile.

//Oddly, with the #ifdef'd code not included, as is the case
// by just using
// g++ -c tstcase.cc 
// the bug does not occur.  As if the use of the inline member
// somehow hides the virtual function compare()

// This is observed with 19990602 snapshot on Linux i686-glibc2

namespace VA {

  namespace VT {

  class string;



  const int ValueTypeVersion = 0X1;

  enum BaseRepresentationType { IntRep,
                                RationalRep,
                                DoubleRep,
                                CStrRep,
                                CppStringRep,
                                CompoundRep,
                                NilRep };


                               
  enum BaseMembershipTestType { IdentityTest,
                                NonIdentityTest,
                                IntervalTest,
                                AlwaysTrueTest,
                                NeverTrueTest,
                                FunctionTest,
                                MembershipListTest };


  enum CompoundRepTypes { BinarySetOp,
                          HomogenouseProduct,
                          HeterogenousProduct,
                          LispType };

  struct IndexedValue {
    int			d_index;
    void*			d_cachePtr;
  };

  struct RationalValue {
    int			d_numerator;
    int			d_denominator;
  };

  union BasicValueHolder {
    int				d_ival;
    double			d_rval;
    char*				d_char1P;
    wchar_t*			d_char2P;
    string*			d_stringP;
     
    void*				d_complexTypeP;
    IndexedValue		d_cacheable;
    RationalValue		d_rational;
  };



  class ValueType;

  struct ValueStruct {
    BasicValueHolder   d_bVal;
    const ValueType*   d_valType;
    unsigned int		   d_flags;
  };


  class Value : protected ValueStruct {
    friend class VA::VT::ValueType;
  protected:
    enum MaintainFlags { NeedsDeepCopy=0x1,  NeedsDestructor=0x2, UsingIndexing=0x4 };

  public:
    ~Value();

    Value(const Value& bv) throw();

    Value& operator=(const Value& o) throw();

    bool operator==(const Value& o) const throw();

    bool operator!=(const Value& o) const throw() {
      return !(*this == o);
    }

    const ValueType* valType() const throw() { return d_valType; }

    string name() const throw();
    
  protected:
    Value() { d_flags= 0; }

  };  


  struct ValueType {

    virtual int compare(const Value& v1, const Value& v2) const throw();


#ifdef MAKEBUG

    bool operator==(const ValueType& o) const {
      return (compare(*this,o)==0);
    }

#endif

  };
  
  enum RoundStyle { RoundClosest, RoundLower, RoundHigher }; 

  class OrderedSet;

  class OrdVal : public Value {
    friend class ValueTypeIterator;
  public:

    OrdVal(int num, int denom=1) throw();

    OrdVal(const double& d, 
           int denomPrecision=1000, 
           RoundStyle sty=RoundClosest) throw();

    OrdVal(const char* cstr) throw();

    OrdVal(const string& str) throw();

    bool operator<(const OrdVal& o) const;

    bool operator<=(const OrdVal& o) const;

    bool operator>(const OrdVal& o) const {
      return !(*this <= o);
    }

    bool operator>=(const OrdVal& o) {
      return !(*this < o);
    }

    static OrdVal* makeOrdVal(void* ptrToBaseType,
                              BaseRepresentationType bt);

  protected:
    OrdVal(int index, const OrderedSet* s, void* cached= __null ) throw();
    OrdVal() {}

  }; 


  inline bool
  OrdVal::operator<(const OrdVal& o) const {
    return (valType()->compare(*this,o) < 0);
  }


  }
}

// -Josh

// jstern@citilink.com


More information about the Gcc-bugs mailing list