Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Clang and RTTI on VCL components


This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 6 - Last Post: Sep 30, 2015 8:30 AM Last Post By: Anssi Huttunen
Anssi Huttunen

Posts: 5
Registered: 7/13/01
Clang and RTTI on VCL components  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 29, 2015 5:21 AM
Hi all,

After converting a large project from C++ Builder XE5 to C++ Builder 10 Seattle, I wanted to try the 32-bit Clang compiler. After some editing, the application and all my packages compile but unfortunately the application crashes. After some digging, I found out that RTTI is not working as I was expecting.

For example, if you create a simple VCL Forms Application and drop a TListView on the form and put this into the form's constructor:

const string sType = typeid(*ListView1).name();

The application crashes because the const char * pointer returned by typeid() is not valid. This works fine with 'classic' compiler and the class name of TListView is correct.

The above sample is just something I found while tracking my bug. My actual application crashes while down casting with dynamic_cast<> a class that is implemented in a package, so it seems there is something wrong with packages and rtti.

Is this a know limitation in Clang with packages or just a bug?

Edited by: Anssi Huttunen on Sep 29, 2015 5:22 AM
Arkady Semylio

Posts: 87
Registered: 9/18/15
Re: Clang and RTTI on VCL components  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 29, 2015 5:35 AM   in response to: Anssi Huttunen in response to: Anssi Huttunen
Anssi Huttunen wrote:

Is this a know limitation in Clang with packages or just a bug?

AFAIK, neither limitation or bug as the result of std::typeinfo::name() is unspecified.
It could return anything, as return a single string for all types, maybe even an empty
string if possible.

It's not a good idea to rely on typeinfo::name.

Bye
Anssi Huttunen

Posts: 5
Registered: 7/13/01
Re: Clang and RTTI on VCL components  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 29, 2015 5:50 AM   in response to: Arkady Semylio in response to: Arkady Semylio
Arkady Semylio wrote:
Anssi Huttunen wrote:

Is this a know limitation in Clang with packages or just a bug?

AFAIK, neither limitation or bug as the result of std::typeinfo::name() is unspecified.
It could return anything, as return a single string for all types, maybe even an empty
string if possible.

It's not a good idea to rely on typeinfo::name.

Bye

That is a good point, I remember reading that as well!

I changed my example by dropping a TButton on the form as well. If I compare the type_info references like this:

if (typeid(*Button1) != typeid(*ListView1))
{
//...
}

the Clang compilation crashes. Classic compilation doesn't crash.
Josh Kelley

Posts: 75
Registered: 3/6/08
Re: Clang and RTTI on VCL components
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 29, 2015 6:42 AM   in response to: Anssi Huttunen in response to: Anssi Huttunen
On 9/29/2015 8:50 AM, Anssi Huttunen wrote:
Arkady Semylio wrote:
AFAIK, neither limitation or bug as the result of std::typeinfo::name() is unspecified.
It could return anything, as return a single string for all types, maybe even an empty
string if possible.

That is a good point, I remember reading that as well!

Although the contents of std::type_info::name() are
implementation-defined, it is defined as returning a null-terminated string.

Clang's typeid works for non-Delphi-style classes (anything that isn't
__declspec(delphiclass) and doesn't derive from TObject), and typeid
works in bcc32, so this appears to be a bug in the Clang-based
compilers. You should log a bug on quality.embarcadero.com.

--
Josh Kelley
Anssi Huttunen

Posts: 5
Registered: 7/13/01
Re: Clang and RTTI on VCL components  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 29, 2015 10:04 PM   in response to: Josh Kelley in response to: Josh Kelley
Josh Kelley wrote:
Clang's typeid works for non-Delphi-style classes (anything that isn't
__declspec(delphiclass) and doesn't derive from TObject), and typeid
works in bcc32, so this appears to be a bug in the Clang-based
compilers. You should log a bug on quality.embarcadero.com.

I'll do that. Thanks for your help!
Anssi Huttunen

Posts: 5
Registered: 7/13/01
Re: Clang and RTTI on VCL components  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 29, 2015 11:06 PM   in response to: Anssi Huttunen in response to: Anssi Huttunen
Submitted as RSP-12474
Anssi Huttunen

Posts: 5
Registered: 7/13/01
Re: Clang and RTTI on VCL components  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 30, 2015 8:30 AM   in response to: Anssi Huttunen in response to: Anssi Huttunen
For your information. I was able reproduce my original problem of access violation during dynamic_cast<> in a simple example project. This has been submitted as RSP-12479.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02