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

Intel 19.3 - RTTI typeinfo included on type compiled with /GR-

jase439
Beginner
508 Views

My question pertains specifically to the Windows compiler (v19 Update 3) running in VS2017 v15.9.9.

I have a class in a third-party lib that is compiled with no RTTI (/GR-). This library defines several C++ types.

My project subclasses one of these library types. The compilation (.cpp) unit that contains this subclassed type is also compiled with /GR-. In the client's calling function (which resides in a compilation (.cpp) unit compiled WITH RTTI enabled), I am finding that typeinfo is being injected anyway into instances of these "non-RTTI" types, such that statements like dynamic_cast<> and typeid(…) succeed. This behavior is inconsistent with what I observe under Linux and GCC which emits the expected:

"undefined reference to 'typeinfo' for 'ident'"

I do not believe the compiler should be silently "elevating" these non-RTTI types to RTTI types as it allows parts of the language to be used which are otherwise (and should be) unsafe. The only way I can achieve conformance with types compiled with /GR- is to ban RTTI for ALL compilation units in the project. This seems unnecessarily restrictive to clients. 

Is this behavior known? Expected?

Thanks.

0 Kudos
4 Replies
Viet_H_Intel
Moderator
508 Views

Will you see the same problem if you compile with cl?

Thanks,

0 Kudos
jase439
Beginner
508 Views

Viet Hoang (Intel) wrote:

Will you see the same problem if you compile with cl?

Yes, I do see the same behavior with cl. Clang and GCC seem to enforce the restriction with -fno-rtti. I don't know what the behavior of the Intel compiler under Linux is.

0 Kudos
Viet_H_Intel
Moderator
508 Views

Intel compiler is compatible with GCC on Linux and is compatible with Microsoft on Windows. That fact that you see the same behavior with cl, then it's likely not icl issue.

0 Kudos
jase439
Beginner
508 Views

Does that mean language conformance is limited to whatever the host compiler provides and not ICC?

0 Kudos
Reply