egcs-1.0.2 suggestion about error message

Munagala V. S. Ramanath ram@netcom.com
Mon Apr 20 10:15:00 GMT 1998


The following program correctly produces this error message:

bug4.C: In function `int main()':
bug4.C:17: cannot dynamic_cast `q' (of type `struct X *') to type `struct Y *'

It would be more helpful, especially to C++ novices, if it was a little
more explicit about the problem and said something like:
    "source of dynamic_cast must have at least one virtual member
    function"

-------  CUT HERE  ------------------------------------  CUT HERE  -----
// egcs-1.0.2 correctly produces a diagnostic here that could be more
// explicit about the problem
//
#include <stream.h>

struct X {
    // source of dynamic_cast must have at least one virtual member
    //virtual ~X(){};
};
struct Y : X {
};

main( )
{
    Y *p1 = new Y, *p2;
    X *q = p1;
    p2 = dynamic_cast<Y *>( q );
    return 0;
}



More information about the Gcc-bugs mailing list