C++ 5.x: Runtime Problems When Calling Virtual Functions Or Using Dynamic Cast
(Doc ID 1334298.1)
Last updated on DECEMBER 23, 2022
Applies to:
Oracle Solaris Studio - Version Forte Developer 6 Update 2 to 12.6 [Release 6.0 to 12]Oracle Solaris on SPARC (32-bit)
Oracle Solaris on SPARC (64-bit)
Oracle Solaris on x86 (32-bit)
Oracle Solaris on x86-64 (64-bit)
Symptoms
In a complex class hierarchy where multiple inheritance is used, one or several of the following symptoms are observed in a C++ application compiled with Sun Studio or Oracle Solaris Studio Compilers:
- Runtime problems using virtual functions, such as calling the wrong function, or calling a virtual destructor instead of a virtual function.
- Runtime problems using dynamic_cast or runtime type information (RTTI), such as getting the wrong type.
Changes
The problem can occur only if the following conditions are all met:
- C++ 5.x on Solaris in default -compat=5 mode
- Multiple inheritance is used where:
A. One or more classes or struct inherits from a virtual base class that contains no data member.
B. The virtual base class that contains no data member is NOT found first in a depth-first left-to-right scan of the inheritance tree. In other words, it is NOT at the bottom of the left-most branch.
Example basic class hierarchy where the problem might be observed:
public:
// no data members, like this:
virtual void foo() = 0;
virtual ~VB() { }
};
class B : public virtual V { ... };
class C : public virtual V { ... };
class D : public B, public C { ... };
D inherits from the virtual base class V twice, once through B, and once through C:
V
/ \
B C
\ /
D
Basic example code where the wrong virtual function is called:
Cause
To view full details, sign in with your My Oracle Support account. |
|
Don't have a My Oracle Support account? Click to get started! |
In this Document
Symptoms |
Changes |
Cause |
Solution |
Additional Information |