Monday, December 14, 2009

Virtual Inheritance.

I found a bug recently that was causing a crash only on a Solaris 10 build, but the same code was fine on Win32. I eventually tracked it down to the Sun compiler not generating the correct code for a virtual inheritance situation. It was a multiple inheritance situation, and one of the parents was a pure abstract interface class, so it's not like the design was really ugly, or the situation was particularly complex. There was only one implementation of the virtual method for the class, and the abstract interface was derived virtually. Calling the method on the class worked fine, but calling the method on a const abstract base class reference (where the method was declared) returned fine, but the returned object caused a crash as soon as it was used. The method was there, but the compiler didn't hook it up in the virtual method table. It hooked something up though. Bizarre. I removed the virtual keyword, and everything worked fine.
The Sun compiler is Flakey.

No comments: