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]

egcs-971016 bug: wrong constructor called, virtual base class.


If this is not a bug, it is certainly very surprising behavior. The following
program prints 'default cons called' instead of 'int cons called'.

When N1(void) is removed, we get

b3.cc: In method `N3::N3(int)':
b3.cc:16: no matching function for call to `N1::N1 ()'
b3.cc:7: candidates are: N1::N1(const N1 &)
b3.cc:6:                 N1::N1(int)


C++ source
--------------------------------------------------
#include <stream.h>

struct N1 {
  N1(void)    { cout << "default cons called" << endl; }
  
  N1(int)      { cout << "int cons called" << endl;}
};

class N2 : public virtual N1 {
public:
  N2(int c) : N1(c) {}
};

class N3 : public N2 {
public:
  N3(int c) : N2(c) {}
};

main()
{
  N3(1);
}
--------------------------------------------------

compilation:

--------------------------------------------------
/export/home/users/joseph/egcs-971016/bin/g++     -v b3.cc   -o b3
Reading specs from
/export/home/users/joseph/egcs-971016/lib/gcc-lib/sparc-sun-solaris2.5/egcs-2.90.13/specs
gcc version egcs-2.90.13 971016 (gcc2-970802 experimental)

/export/home/users/joseph/egcs-971016/lib/gcc-lib/sparc-sun-solaris2.5/egcs-2.90.13/cpp
-lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus
-D__GNUC_MINOR__=90 -Dsun -Dsparc -Dunix -D__svr4__ -D__SVR4
-D__GCC_NEW_VARARGS__ -D__sun__ -D__sparc__ -D__unix__ -D__svr4__ -D__SVR4
-D__GCC_NEW_VARARGS__ -D__sun -D__sparc -D__unix -Asystem(unix) -Asystem(svr4)
-Acpu(sparc) -Amachine(sparc) -D__EXCEPTIONS b3.cc /var/tmp/cca001bo.ii
GNU CPP version egcs-2.90.13 971016 (gcc2-970802 experimental) (sparc)
#include "..." search starts here:
#include <...> search starts here:
 /export/home/users/joseph/egcs-971016/include/g++
 /usr/local/include
 /export/home/users/joseph/egcs-971016/sparc-sun-solaris2.5/include

/export/home/users/joseph/egcs-971016/lib/gcc-lib/sparc-sun-solaris2.5/egcs-2.90.13/include
 /usr/include
End of search list.

/export/home/users/joseph/egcs-971016/lib/gcc-lib/sparc-sun-solaris2.5/egcs-2.90.13/cc1plus
/var/tmp/cca001bo.ii -quiet -dumpbase b3.cc -version -o /var/tmp/cca001bo.s
GNU C++ version egcs-2.90.13 971016 (gcc2-970802 experimental)
(sparc-sun-solaris2.5) compiled by GNU C version 2.7.2.2.
 /usr/ccs/bin/as -V -Qy -s -o /var/tmp/cca001bo1.o /var/tmp/cca001bo.s
/usr/ccs/bin/as: SC4.0 dev 15 Feb 1995

/export/home/users/joseph/egcs-971016/lib/gcc-lib/sparc-sun-solaris2.5/egcs-2.90.13/ld
-V -Y P,/usr/ccs/lib:/usr/lib -Qy -o b3
/export/home/users/joseph/egcs-971016/lib/gcc-lib/sparc-sun-solaris2.5/egcs-2.90.13/crt1.o
/export/home/users/joseph/egcs-971016/lib/gcc-lib/sparc-sun-solaris2.5/egcs-2.90.13/crti.o
/usr/ccs/lib/values-Xa.o
/export/home/users/joseph/egcs-971016/lib/gcc-lib/sparc-sun-solaris2.5/egcs-2.90.13/crtbegin.o
-L/export/home/users/joseph/egcs-971016/lib/gcc-lib/sparc-sun-solaris2.5/egcs-2.90.13
-L/export/home/users/joseph/egcs-971016/sparc-sun-solaris2.5/lib
-L/usr/ccs/bin -L/usr/ccs/lib -L/export/home/users/joseph/egcs-971016/lib
/var/tmp/cca001bo1.o -lstdc++ -lm -lgcc -lc -lgcc
/export/home/users/joseph/egcs-971016/lib/gcc-lib/sparc-sun-solaris2.5/egcs-2.90.13/crtend.o
/export/home/users/joseph/egcs-971016/lib/gcc-lib/sparc-sun-solaris2.5/egcs-2.90.13/crtn.o
ld: Software Generation Utilities (SGU) SunOS/ELF (LK-2.0 (S/I) - versioning)

Compilation finished at Sat Oct 18 16:34:26
--------------------------------------------------

running

--------------------------------------------------
./b3
default cons called
--------------------------------------------------


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