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]

Non-intuitive conversion warning



Maybe this is a problem with my understanding of C++, but I'd expect the
compiler to chose the constructor "Derived2(const Derived1 &)" over the
other one silently in the last statement of the following example. 
-----------------------------------------------------------------------
class Base {};
class Derived1 : public Base {};

class Derived2 : public Derived1 {
  public:
    Derived2 (const Base &);
    Derived2 (const Derived1 &);
};


void  foo() {
  Derived1 q;
  Derived2 a = q;
};
-----------------------------------------------------------------------
The output of egcs-ss-19980621 is appended. Note that if the last
statement is changed to "Derived2 a(q);", the message goes away.

Regards
  Wolfgang

-----------------------Output------------------------------------------
wolf@sol:/home/wolf/program/grid/deal.II/source/grid >/home/wolf/bin/gcc/bin/c++ -v -c t1.cc
Reading specs from
/home/wolf/bin/egcs-19980621/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.91.42/specs
gcc version egcs-2.91.42 19980621 (gcc2 ss-980502 experimental)

/home/wolf/bin/egcs-19980621/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.91.42/cpp
-lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus
-D__GNUC_MINOR__=91 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__
-D__linux__ -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -Di386
-Asystem(unix) -Acpu(i386) -Amachine(i386) -D__pentium__ -D__i586__
-D__i386__ -Asystem(unix) -Acpu(i386) -Amachine(i386) -D__pentium__
-D__i586__ t1.cc /tmp/cca24129.ii
GNU CPP version egcs-2.91.42 19980621 (gcc2 ss-980502 experimental) (i386
Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /home/wolf/bin/egcs-19980621/include/g++
 /usr/local/include
 /home/wolf/bin/egcs-19980621/i586-pc-linux-gnulibc1/include

/home/wolf/bin/egcs-19980621/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.91.42/include
 /usr/include
End of search list.

/home/wolf/bin/egcs-19980621/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.91.42/cc1plus
/tmp/cca24129.ii -quiet -dumpbase t1.cc -version -o /tmp/cca24129.s
GNU C++ version egcs-2.91.42 19980621 (gcc2 ss-980502 experimental)
(i586-pc-linux-gnulibc1) compiled by GNU C version egcs-2.91.42 19980621
(gcc2 ss-980502 experimental).
t1.cc: In function `void foo()':
t1.cc:13: warning: choosing `Derived2::Derived2(const Derived1 &)' over `Derived2::Derived2(const Base &)'
t1.cc:13: warning:   for conversion from `' to `Derived2'
t1.cc:13: warning:   because conversion sequence for the argument is better
--------------------------------------------------------------------------





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