Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

dynamic_cast troubles

vpozdyayev
Beginner
2,865 Views

Hello.This code throws an exception when compiled with ICC 12.1.5 (works fine with MSVC and GCC):[cpp]class A { public: virtual void _dummy() { } }; class B: virtual public A { }; class C: virtual public A, public B { }; int main() { auto c = new C; auto a = dynamic_cast< A * >( c ); auto b = dynamic_cast< B * >( c ); auto ca = dynamic_cast< C * >( a ); // ok auto cb = dynamic_cast< C * >( b ); // std::__non_rtti_object return 0; } [/cpp] The culprit seems to be the "class B: virtual public A" part. Just "class B: public A" works without exceptions.----Regards,Vladimir

0 Kudos
27 Replies
SergeyKostrov
Valued Contributor II
565 Views
>>In my case (ICC 13.1.0 on MSVS 2012), the exception has been originally caused by a nullptr dereference >>in FindCompleteObject, just like with ICC 12.1.5. I didn't repeat a test with ICC 12 but I confirm that I saw some processing with FindCompleteObject internal function when I was doing debugging with ICC 13 and VS 2008 PE. Brandon, I can see that some time ago you've made a statement "...I'm not catching any exceptions with this code....". So, what else should we do in order to prove that there is a problem? Please let us know. Best regards, Sergey
0 Kudos
Brandon_H_Intel
Employee
565 Views

Hi all,

Sorry for missing the updates on this thread. With the extra information, I could reproduce the thrown RTTI exception, and I've submitted a problem report to our front-end team.  Interestingly, if class B contains its own virtual function, the exception no longer gets thrown.

0 Kudos
SergeyKostrov
Valued Contributor II
565 Views
What happened to the 1st original post? As soon as Brandon made his post the original post is re-formatted to almost unreadable form.
0 Kudos
SergeyKostrov
Valued Contributor II
565 Views
>>... Interestingly, if class B contains its own virtual function, the exception no longer gets thrown... Hi Brandon, Do you mean a modification like this one: ... class B : virtual public A { public: virtual void _dummy() { } }; ...
0 Kudos
vpozdyayev
Beginner
565 Views

Thanks, Brandon.

> Interestingly, if class B contains its own virtual function, the exception no longer gets thrown

That's right; as I have mentioned earlier, this problem seems to depend on whether B has any additions to vtable. I am currently using a virtual destructor in A as a workaround (which results in automatic generation of default virtual ~B() for all B classes).

----
Regars,
Vladimir 

0 Kudos
SergeyKostrov
Valued Contributor II
565 Views
>>>> Interestingly, if class B contains its own virtual function, the exception no longer gets thrown >> >>That's right; as I have mentioned earlier, this problem seems to depend on whether B has any additions to vtable. I am >>currently using a virtual destructor in A as a workaround (which results in automatic generation of default virtual ~B() for >>all B classes). Even if both "tricks" could be considered as workarounds the initial test case ( in post #1 ) should work without throwing the exception. Best regards, Sergey
0 Kudos
Brandon_H_Intel
Employee
565 Views

Hi all,

The original issue with a std::__non_rtti_object exception getting thrown is resolved in the latest 13.1 and 14.0 compilers (Intel(R) C++ Composer XE 2013 and 2013 SP1 products). Let me know if you have any further issues.

0 Kudos
Reply