My Oracle Support Banner

C++ 5.x: Runtime Problems When Calling Virtual Functions Or Using Dynamic Cast (Doc ID 1334298.1)

Last updated on JANUARY 05, 2024

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:

Changes

The problem can occur only if the following conditions are all met:

  1. C++ 5.x on Solaris in default -compat=5 mode
  2. 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:

class VB { // used as a virtual base class
   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

My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.