Opened 4 days ago

#896 new enhancement

Implement dynamic cast support in C++ runtime

Reported by: Jiri Svoboda Owned by:
Priority: major Milestone:
Component: helenos/unspecified Version: mainline
Keywords: Cc:
Blocker for: #526 Depends on:
See also:

Description

I am trying to port DOSBox to HelenOS. DOSBox, written in C++, uses dynamic_cast<T>(v). Currently this always returns nullptr in HelenOS.

The reason is that, for the truly dynamic cases, the C++ compiler generates a call to the runtime function __dynamic_cast()

In HelenOS a stub is implemented in uspace/lib/cpp/src/__bits/runtime.cpp, which always returns nullptr.

In this regard GCC follows the Intel Itanium C++ ABI. The necessary documentation is here:

(You can found it in the docs section of our wiki).

An example implementation from the Android Open Source project:

In essence the function must walk the RTTI graph and determine whether the type conversion is valid, i.e. the object can be converted to the destination type. It also needs to correctly adjust the pointer to point to the required part of the object.

Unfortunately the specification is not easy to read and the C++ language itself is not easy to understand. Also further complicated by multiple inheritance (e.g. if we convert to type T from which we inherit multiple times, the conversion is ambiguous and should return nullptr).

Change History (0)

Note: See TracTickets for help on using tickets.