Re: typeid() headaches (library to main executable)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Wed, Apr 27, 2005 at 06:46:11AM -0500, Eljay Love-Jensen wrote:
> Hi Andreas,
> 
> Note that "GCC" 2.96 is really a maverick (unsanctioned by GNU) release from Red Hat.  There wasn't a GCC 2.96, per se.  The backstory behind it is interesting, and available on-line (q.v. via Google), but isn't germane so I won't go into details.
Yup, I remember that Red Hat messup VERY clearly (I could have mentioned that).

> So when the GCC documentation speaks of a new C++ ABI in GCC 3.0, that's new from GCC 2.95.  And the new C++ ABI underwent some incompatible changes between 3.0 and 3.1, and 3.1 and 3.2.  As I understand the situation, 3.2 - 3.3 - 3.4 have a compatible C++ ABI.  I'm not sure about the recent GCC 4.0.
Oook. I was afraid already that 2.95(/6) was already too close to 3.0
to still be different from the 3.x model.

> Anyway, given the description you provided, I tried to recreate the situation and was unable to reproduce the undefined reference you are running into.
That's because (I didn't mention this either) in this form the program is
perfect. The problem only occurs once you disable one of the inlined virtual
method implementations.
...which would then be the situation I'm in, since due to pre-defined macro use
I cannot implement some virtual methods in the .h file - well, I perhaps
could, but this would strongly deviate from the usual way to do it.

> I also used your program.h, program.cpp, libtest.cpp and makefile -- and was unable to reproduce the undefined reference you are running into.  Rather I'm seeing this...
> 
> > make
> g++  -o program program.cpp
> program.cpp:6: redefinition of `void CTestClass::mytest()'
> program.h:13: `virtual void CTestClass::mytest()' previously defined here
> 
> program.cpp:6: no `void CTestClass::mytest()' member function declared in class
>    `CTestClass'
> make: *** [program] Error 1
> 
> ...which appears to be due to CTestClass::mytest being defined twice.
> 
> Could you fix your short example code that reproduces the problem?
Doh, sorry. That mytest() in program.cpp shouldn't have been there.

> Also, since you specified ALL your virtual functions as inline, you may want to consider -fkeep-inline-functions.  As I understand it, the type information is generated with the first virtual (non-inline) function is generated.  If all your virtual functions are inline (which is very, very odd, by the way, since the whole point to a virtual function is to be accessed polymorphically through the virtual function pointer table, and you cannot have a virtual function pointer access to a method that is inlined), the compiler may not trigger generation of type information.
True, since an inlined function (usually) is a non-function.
Still, that inlining is only done to try to get to work a typeid() in a library
on a main program class at all. A last desperate effort.

I'm beginning to believe that Thou Shalt Not use typeid() on classes with
undefined virtual members with g++. But maybe I'm simply doing something very
stupid...

> Another consideration is that your base class CBaseTestClass does not have a virtual destructor, yet is used as a public base class for CTestClass.  Either you should put in a virtual destructor for CBaseTestClass, or you should make the base class private in CTestClass.
Right, I didn't care about this aspect in this sample, though.
(and in fact in my real class the dtor *is* virtual).

Thank you for your VERY FAST reply,

Andreas Mohr

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux