﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	field_blocks	field_dependson	field_seealso
896	Implement dynamic cast support in C++ runtime	Jiri Svoboda		"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:
   * [https://itanium-cxx-abi.github.io/cxx-abi/abi.html Intel Itanium C++ ABI]
   * [https://kolegite.com/EE_library/standards/ARM_ABI/cppabi32.pdf C++ ABI for the ARM architecture]
(You can found it in the docs section of our wiki).

An example implementation from the Android Open Source project:
   * [https://android.googlesource.com/platform/abi/cpp/+/eb789ea833d8d800662b67914d9c1785a58c2caa/src/dynamic_cast.cc dynamic_cast.cc]

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).
"	enhancement	new	major		helenos/unspecified	mainline				#526		
