[comp.lang.c++] cfront 2.0 bug in base class initialization

sdm@cs.brown.edu (Scott Meyers) (01/16/90)

The following program demonstrates what is almost certainly a bug in cfront
2.0.  The base class has two constructors, only the first of which is
needed.  But if the second constructor is missing, then the first one is
never called and the base part of the derived object doesn't get
initialized.  

  #include <iostream.h>

  class Base  {
    public:
      Base(class Derived &p) { cout << "Base::Base -- 1\n"; }
      Base(Base &g) { cout << "Base::Base -- 2\n"; }
        // This second constructor is never called, but if it's not here,
        // then the first constructor won't be called and the Base part of
        // a Derived object will be uninitialized.
  };

  class Derived: public Base {
    public:
      Derived(): Base(*this) { cout << "Derived::Derived\n"; }
  };


  main()
  {
      Derived *pd = new Derived;
  }

g++ properly handles initialization without the superfluous constructor.

If I'm mistaken, I'd appreciate it if somebody would set me straight.

Scott